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
Post a Comment