C Tutorial
'&' is used to get the address of the variable.
'*' is used to get the value at address.
#include<stdio.h> void main() { int val = 5; printf("Address of val = %u\n", &val); printf("Value of val = %d\n", val); printf("Value of val using address = %d\n", *(&val)); }Output:
$ cc pointer1.c $ ./a.out Address of val = 43479740 Value of val = 5 Value of val using address = 5
int *j;
Value at the address contained in j is an int data type.
#include<stdio.h> void main() { int i = 5; int *j; j = &i; printf("Address of i = %u\n", &i); printf("Value of i = %d\n", i); printf("Address of j = %u\n", &j); printf("Value of j = %d\n", j); printf("Value of i = %d\n", *(&i)); printf("Value of i = %d\n", *j); }Output:
$ cc pointer1.c $ ./a.out Address of i = 4049270524 Value of i = 5 Address of j = 4049270512 Value of j = -245696772 Value of i = 5 Value of i = 5
C Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page