Tuesday, April 7, 2015

Reference and Dereference operator

Algorithm
Step 1 : Start
Step 2 : Initialize x to 10
Step 3 : Print the value of x
Step 4 : Print the address of x using address operator
Step 5 : Print the value of x by dereferencing the address operator
Step 6 : Stop

Program (refderef.c)
/* Data and address */
#include <stdio.h>
main()
{
int x;
x=10;
printf("Value of x is %d",x);
printf("\nAddress of x is %u",&x);
printf("\nValue of x is %d\n",*(&x));
}



Output
[vijai@localhost pointer]$ gcc refderef.c
[vijai@localhost pointer]$ ./a.out
Value of x is 10
Address of x is 3221216948
Value of x is 10

No comments:

Post a Comment