702 views
3 votes
3 votes
#include <iostream>
using namespace std;

int main()
{
    int i = 10;
    int *p;
    p = &i;
    printf("%u\n%u\n%u", *&p, &*p, &i);
}

All will give same answer.

Suppose Adress of i = 100, and since p is pointing to i, it will have value at p = 100, and suppose address of p = 200.

How, to evaluate it?

1 Answer

2 votes
2 votes

We have to understand here this way :

a) 'p' is itself a pointer variable . So taking the address of it followed by dereferencing will give back 'p' itself . And 'p' is nothing but  the address of 'i' .

b) Similarly if we dereference 'p' we get 'i' as 'p' contains the address of 'i' . Now when we again put '&' on it means that we are referring to the address of i only and hence in short we are concerned about &i .

c) The same is given as third argument of printf() in direct form.

Hence all of  :  &*p , *&p and &i will give the same value which is the address of 'i' specifically.

Related questions

0 votes
0 votes
1 answer
1
viral8702 asked Apr 29, 2022
485 views
A frame buffer array is addressed in row major order for a monitor with pixel locations starting from (0,0) and ending with (100,100). What is address of the pixel(6,10)?...
0 votes
0 votes
1 answer
2
Balaji Jegan asked Jul 23, 2018
419 views
3 votes
3 votes
1 answer
3