0 votes
in Programming by (2k points)
int *p = NULL ,c , *q;
p = &c;
q = p; 

printf ("%d and %d ",&p, &q );

Output: 2686788 and 2686780

========================= My question is: As far I assume, I thought the memory address will be same, as I have assigned p into q. May be I am wrong.

1 Answer

0 votes
by (2.4k points)

You are printing the address of the pointers themselves, not the pointer values:

// Prints the memory location of the pointers
printf ("%d and %d\n", &p, &q);

// Prints the values of the pointers
printf ("%d and %d\n",  p,  q);

// Prints the values that the pointers point to
printf ("%d and %d\n", *p, *q);

Hope so you find your answer!

131 questions

117 answers


378 users

Welcome to Todayask Q&A, where you can ask questions and receive answers from other members of the community.