+ 2

Questions about Pointer in C

/*As far as I know, when you print pointer without *(asterisk), you print the address of the pointer. And the symbol--&--also indicates the address. However, when I put em side by side, it seems that the address of one pointer and the & of the pointer indicate different values. Would you help me understand why it's happening in this manner?*/ #include <stdio.h> int main() { int r = 7; int* i = &r; printf("%p\n",i); printf("%p\n\n",&i); char*k="h"; printf("%p\n",k); printf("%p\n\n",&k); char* p = "akz"; printf("%p\n",p); printf("%p\n\n",&p); int arr[] = {1,5,9}; int*pp = arr; printf("%p\n",pp); printf("%p\n\n",&pp); return 0; }

15th Apr 2022, 9:15 PM
OTTER
OTTER - avatar
2 Answers
+ 2
If p is a pointer and int r= 5; int *p = &r; p returns address of r that &r &p returns address of pointer p P stores another variable address and *p returns values by pointing &r, r value &p is p address. It has also address. Hope it helps..
15th Apr 2022, 9:58 PM
Jayakrishna 🇼🇳
+ 3
You just answered so perfectly, thank you!
15th Apr 2022, 10:04 PM
OTTER
OTTER - avatar