# pointers and addresses

``````int m=10;
int *ab=&m;

output:
``````

i understand i am intialising a pointer variable ab(not just ab) and when i am printing address of ab instead of *ab why is it not throwing an error as *"ab" does'nt exist ,only "ab" exists.

``````int m=10;
``````

This creates an integer with the value of 10 somewhere in memory.

``````int *ab=&m;
``````

This creates a pointer to an int, and sets it to the address of the integer m (that is, the value of ab is the address of m).

``````printf("address of *ab:%p\n",&*ab);
``````

So two things happen here. First, we dereference ab with *; this is, we actually go to the address held in ab which is where the value of m is stored. Then we get the address of this location with &; namely, the address of m. Hence this is ultimately just the address stored in ab to begin with. It's functionally equivalent to:

``````printf("value of ab:%p\n",ab);
``````

Finally:

``````printf("address of ab:%p\n",&ab);
``````

This is the address of ab, where the pointer itself is stored in memory. So at this location you find ab, the value of which is the address of m.