Pointers to pointers in c programming language

C pointers to pointers: A pointer is pointing to another pointers is called pointers to pointer.


Examples of pointers to pointers in c:


What will be output if you will execute following code?


#include<stdio.h>

int main(){

int s=2,*r=&s,**q=&r,***p=&q;

printf("%d",p[0][0][0]);
return 0;

}


Output: 2

Explanation:


As we know p[i] =*(p+i)

So,

P[0][0][0]=*(p[0][0]+0)=**p[0]=***p

Another rule is: *&i=i

So,

***p=*** (&q) =**q=** (&r) =*r=*(&s) =s=2

4 comments:

Sophia Right said...

A great post without doubt. The information shared is of top quality which has to get appreciated at all levels.

Manmeet Kaur said...

This comment has been removed by the author.

Khamal Fauzan said...

Superb

Khamal Fauzan said...

Superb