Write a C program to illustrate the usage of pointers and its accessibility.
int main() {
int val, *data;
/* get the input data from the user */
printf("Enter the value for val:");
scanf("%d", &val);
/* store the address of the variable 'val' */
data = &val;
/* print the outputs */
printf("val : %d\n", val);
printf("Address of val : 0x%x\n", (int)&val);
printf("data : 0x%x\n", (int)data);
printf("*data : %d\n", *data);
printf("Address of data: 0x%x\n", (int)&data);
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter the value for val:10000
val : 10000
Address of val : 0xbfdafd5c
data : 0xbfdafd5c
*data : 10000
Address of data: 0xbfdafd58
Enter the value for val:10000
val : 10000
Address of val : 0xbfdafd5c
data : 0xbfdafd5c
*data : 10000
Address of data: 0xbfdafd58
No comments:
Post a Comment