c - Declare pointer to pointer to pointer -


i trying understand simple pointers little better clarifying myself address pointer points to, address of pointer , value address refers to. wrote small piece of code:

#include <stdio.h> #include <stdlib.h>  int main() {     int a;     int *p;     int **pp;      = 42;      /* take address of */     p = &a;      /* take address of p */     pp = &p;      printf("address of int &a:                          %p\n\n", &a);     printf("value of a:                                 %d\n\n", a);      printf("address *p points via (void *)p:   %p\n\n", (void *)p);     printf("value *p points via *p:             %d\n\n", *p);     printf("address of *p via (void *)&p:        %p\n\n", (void *)&p);      printf("address **p points via (void *)pp: %p\n\n", (void *)pp);     printf("value **pp points via **pp:         %d\n\n", **pp);     printf("address of **p via (void *)&pp:      %p\n\n", (void *)&pp);     return exit_success; } 

this works expected (please, correct me if made mistakes here.). now, want go 1 level deeper , use pointer pointer pointer ***ppp , assign address pointer pointer pp points address *p points address of a. here how thought it:

#include <stdio.h> #include <stdlib.h>  int main() {     int a;     int *p;     int **pp;     int **ppp;      = 42;      /* take address of */     p = &a;      /* take address of p */     pp = &p;      ppp = &pp;      printf("address of int &a:                               %p\n\n", &a);     printf("value of a:                                      %d\n\n", a);      printf("address *p points via (void *)p:        %p\n\n", (void *)p);     printf("value *p points via *p:                  %d\n\n", *p);     printf("address of *p via (void *)&p:             %p\n\n", (void *)&p);      printf("address **pp points via (void *)pp:     %p\n\n", (void *)pp);     printf("value **pp points via **pp:              %d\n\n", **pp);     printf("address of **pp via (void *)&pp:          %p\n\n", (void *)&pp);      printf("address ***ppp points via (void *)ppp:  %p\n\n", (void *)ppp);      printf("value ***ppp points via ***ppp:          %d\n\n", ***ppp);     printf("address ***ppp points via (void *)&ppp: %p\n\n", (void *)&ppp);      return exit_success; } 

but gives me incompatible pointer warning. explain me why not work , if calls printf() right?

the error in line int **ppp; /* should ***ppp, because you're pointing pointer points one*/


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -