Advertisement
Manhydra

Pointers to Pointers to Pointers to Pointers to Pointers....

Jul 17th, 2013
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.92 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /* (c) 2007 Marc Sylvestre
  4.  * Displaying the relationship between pointers and arrays
  5. */
  6.  
  7. int main(void) {
  8.     int myAge;
  9.     int *pAge = &myAge;     /* points to myAge */
  10.     int **ppAge = &pAge;    /* points to pointer of myAge */
  11.     int ***pppAge = &ppAge; /* points to pointer of pointer of myAge */
  12.     int ****ppppAge = &pppAge; /* points to pointer of pointer of pointer of myAge */
  13.     int *****pppppAge = &ppppAge; /* points to pointer of pointer of pointer of pointer of myAge */
  14.  
  15.     myAge = 30;
  16.  
  17.     printf("Value of myAge: %d\n", myAge);
  18.     printf("Address of myAge: %p\n", &myAge);
  19.     puts("----------------------------");
  20.     printf("Value of *myAge: %d\n", myAge);
  21.     printf("pAge points to address: %p\n", pAge);
  22.     printf("Actual address of pAge: %p\n", &pAge);
  23.     puts("----------------------------");
  24.     printf("value of *pAge: %d\n", *pAge);
  25.     printf("value of pAge[0]: %d\n", pAge[0]);
  26.     printf("pAge points to address: %p\n", pAge);
  27.     printf("Actual address of pAge: %p\n", &pAge);
  28.     puts("----------------------------");
  29.     printf("value of **ppAge: %d\n", **ppAge);
  30.     printf("value of *ppAge[0]: %d\n", *ppAge[0]);
  31.     printf("value of ppAge[0][0]: %d\n", ppAge[0][0]);
  32.     puts("----------------------------");
  33.     printf("*ppAge points to address: %p\n", *ppAge);
  34.     printf("ppAge[0] points to address: %p\n", ppAge[0]);
  35.     printf("ppAge points to address: %p\n", ppAge);
  36.     printf("Actual address of ppAge: %p\n", &ppAge);
  37.     puts("----------------------------");
  38.     printf("value of ***pppAge: %d\n", ***pppAge);
  39.     printf("value of **pppAge[0]: %d\n", **pppAge[0]);
  40.     printf("value of *pppAge[0][0]: %d\n", *pppAge[0][0]);
  41.     printf("value of pppAge[0][0][0]: %d\n", pppAge[0][0][0]);
  42.     puts("----------------------------");
  43.     printf("**pppAge points to address: %p\n", **pppAge);
  44.     printf("*pppAge[0] points to address: %p\n", *pppAge[0]);
  45.     printf("pppAge[0][0] points to address: %p\n", pppAge[0][0]);
  46.     puts("----------------------------");
  47.     printf("*pppAge points to address: %p\n", *pppAge);
  48.     printf("pppAge[0] points to address: %p\n", pppAge[0]);
  49.     printf("pppAge points to address: %p\n", pppAge);
  50.     printf("Actual address of pppAge: %p\n", &pppAge);
  51.     puts("----------------------------");
  52.     printf("value of ****ppppAge: %d\n", ****ppppAge);
  53.     printf("value of ***ppppAge[0]: %d\n", ***ppppAge[0]);
  54.     printf("value of **ppppAge[0][0]: %d\n", **ppppAge[0][0]);
  55.     printf("value of *ppppAge[0][0][0]: %d\n", *ppppAge[0][0][0]);
  56.     printf("value of ppppAge[0][0][0][0]: %d\n", ppppAge[0][0][0][0]);
  57.     puts("----------------------------");
  58.     printf("***ppppAge points to address: %p\n", ***ppppAge);
  59.     printf("**ppppAge[0] points to address: %p\n", **ppppAge[0]);
  60.     printf("*ppppAge[0][0] points to address: %p\n", *ppppAge[0][0]);
  61.     printf("ppppAge[0][0][0] points to address: %p\n", ppppAge[0][0][0]);
  62.     puts("----------------------------");
  63.     printf("**ppppAge points to address: %p\n", **ppppAge);
  64.     printf("*ppppAge[0] points to address: %p\n", *ppppAge[0]);
  65.     printf("ppppAge[0][0] points to address: %p\n", ppppAge[0][0]);
  66.     puts("----------------------------");
  67.     printf("*ppppAge points to address: %p\n", *ppppAge);
  68.     printf("ppppAge[0] points to address: %p\n", ppppAge[0]);
  69.     puts("----------------------------");
  70.     printf("ppppAge points to address: %p\n", ppppAge);
  71.     printf("Actual address of ppppAge: %p\n", &ppppAge);
  72.     puts("----------------------------");
  73.     printf("value of *****pppppAge: %d\n", *****pppppAge);
  74.     printf("value of ****pppppAge[0]: %d\n", ****pppppAge[0]);
  75.     printf("value of ***pppppAge[0][0]: %d\n", ***pppppAge[0][0]);
  76.     printf("value of **pppppAge[0][0][0]: %d\n", **pppppAge[0][0][0]);
  77.     printf("value of *pppppAge[0][0][0][0]: %d\n", *pppppAge[0][0][0][0]);
  78.     printf("value of pppppAge[0][0][0][0][0]: %d\n", pppppAge[0][0][0][0][0]);
  79.     puts("----------------------------");
  80.     printf("****pppppAge points to address: %p\n", ****pppppAge);
  81.     printf("***pppppAge[0] points to address: %p\n", ***pppppAge[0]);
  82.     printf("**pppppAge[0][0] points to address: %p\n", **pppppAge[0][0]);
  83.     printf("*pppppAge[0][0][0] points to address: %p\n", *pppppAge[0][0][0]);
  84.     printf("pppppAge[0][0][0][0] points to address: %p\n", pppppAge[0][0][0][0]);
  85.     puts("----------------------------");
  86.     printf("***pppppAge points to address: %p\n", ***pppppAge);
  87.     printf("**pppppAge[0] points to address: %p\n", **pppppAge[0]);
  88.     printf("*pppppAge[0][0] points to address: %p\n", *pppppAge[0][0]);
  89.     printf("pppppAge[0][0][0] points to address: %p\n", pppppAge[0][0][0]);
  90.     puts("----------------------------");
  91.     printf("**pppppAge points to address: %p\n", **pppppAge);
  92.     printf("*pppppAge[0] points to address: %p\n", *pppppAge[0]);
  93.     printf("pppppAge[0][0] points to address: %p\n", pppppAge[0][0]);
  94.     puts("----------------------------");
  95.     printf("*pppppAge points to address: %p\n", *pppppAge);
  96.     printf("pppppAge[0] points to address: %p\n", pppppAge[0]);
  97.     printf("pppppAge points to address: %p\n", pppppAge);
  98.     printf("Actual address of pppppAge: %p\n", &pppppAge);
  99.  
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement