Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /* (c) 2007 Marc Sylvestre
- * Displaying the relationship between pointers and arrays
- */
- int main(void) {
- int myAge;
- int *pAge = &myAge; /* points to myAge */
- int **ppAge = &pAge; /* points to pointer of myAge */
- int ***pppAge = &ppAge; /* points to pointer of pointer of myAge */
- int ****ppppAge = &pppAge; /* points to pointer of pointer of pointer of myAge */
- int *****pppppAge = &ppppAge; /* points to pointer of pointer of pointer of pointer of myAge */
- myAge = 30;
- printf("Value of myAge: %d\n", myAge);
- printf("Address of myAge: %p\n", &myAge);
- puts("----------------------------");
- printf("Value of *myAge: %d\n", myAge);
- printf("pAge points to address: %p\n", pAge);
- printf("Actual address of pAge: %p\n", &pAge);
- puts("----------------------------");
- printf("value of *pAge: %d\n", *pAge);
- printf("value of pAge[0]: %d\n", pAge[0]);
- printf("pAge points to address: %p\n", pAge);
- printf("Actual address of pAge: %p\n", &pAge);
- puts("----------------------------");
- printf("value of **ppAge: %d\n", **ppAge);
- printf("value of *ppAge[0]: %d\n", *ppAge[0]);
- printf("value of ppAge[0][0]: %d\n", ppAge[0][0]);
- puts("----------------------------");
- printf("*ppAge points to address: %p\n", *ppAge);
- printf("ppAge[0] points to address: %p\n", ppAge[0]);
- printf("ppAge points to address: %p\n", ppAge);
- printf("Actual address of ppAge: %p\n", &ppAge);
- puts("----------------------------");
- printf("value of ***pppAge: %d\n", ***pppAge);
- printf("value of **pppAge[0]: %d\n", **pppAge[0]);
- printf("value of *pppAge[0][0]: %d\n", *pppAge[0][0]);
- printf("value of pppAge[0][0][0]: %d\n", pppAge[0][0][0]);
- puts("----------------------------");
- printf("**pppAge points to address: %p\n", **pppAge);
- printf("*pppAge[0] points to address: %p\n", *pppAge[0]);
- printf("pppAge[0][0] points to address: %p\n", pppAge[0][0]);
- puts("----------------------------");
- printf("*pppAge points to address: %p\n", *pppAge);
- printf("pppAge[0] points to address: %p\n", pppAge[0]);
- printf("pppAge points to address: %p\n", pppAge);
- printf("Actual address of pppAge: %p\n", &pppAge);
- puts("----------------------------");
- printf("value of ****ppppAge: %d\n", ****ppppAge);
- printf("value of ***ppppAge[0]: %d\n", ***ppppAge[0]);
- printf("value of **ppppAge[0][0]: %d\n", **ppppAge[0][0]);
- printf("value of *ppppAge[0][0][0]: %d\n", *ppppAge[0][0][0]);
- printf("value of ppppAge[0][0][0][0]: %d\n", ppppAge[0][0][0][0]);
- puts("----------------------------");
- printf("***ppppAge points to address: %p\n", ***ppppAge);
- printf("**ppppAge[0] points to address: %p\n", **ppppAge[0]);
- printf("*ppppAge[0][0] points to address: %p\n", *ppppAge[0][0]);
- printf("ppppAge[0][0][0] points to address: %p\n", ppppAge[0][0][0]);
- puts("----------------------------");
- printf("**ppppAge points to address: %p\n", **ppppAge);
- printf("*ppppAge[0] points to address: %p\n", *ppppAge[0]);
- printf("ppppAge[0][0] points to address: %p\n", ppppAge[0][0]);
- puts("----------------------------");
- printf("*ppppAge points to address: %p\n", *ppppAge);
- printf("ppppAge[0] points to address: %p\n", ppppAge[0]);
- puts("----------------------------");
- printf("ppppAge points to address: %p\n", ppppAge);
- printf("Actual address of ppppAge: %p\n", &ppppAge);
- puts("----------------------------");
- printf("value of *****pppppAge: %d\n", *****pppppAge);
- printf("value of ****pppppAge[0]: %d\n", ****pppppAge[0]);
- printf("value of ***pppppAge[0][0]: %d\n", ***pppppAge[0][0]);
- printf("value of **pppppAge[0][0][0]: %d\n", **pppppAge[0][0][0]);
- printf("value of *pppppAge[0][0][0][0]: %d\n", *pppppAge[0][0][0][0]);
- printf("value of pppppAge[0][0][0][0][0]: %d\n", pppppAge[0][0][0][0][0]);
- puts("----------------------------");
- printf("****pppppAge points to address: %p\n", ****pppppAge);
- printf("***pppppAge[0] points to address: %p\n", ***pppppAge[0]);
- printf("**pppppAge[0][0] points to address: %p\n", **pppppAge[0][0]);
- printf("*pppppAge[0][0][0] points to address: %p\n", *pppppAge[0][0][0]);
- printf("pppppAge[0][0][0][0] points to address: %p\n", pppppAge[0][0][0][0]);
- puts("----------------------------");
- printf("***pppppAge points to address: %p\n", ***pppppAge);
- printf("**pppppAge[0] points to address: %p\n", **pppppAge[0]);
- printf("*pppppAge[0][0] points to address: %p\n", *pppppAge[0][0]);
- printf("pppppAge[0][0][0] points to address: %p\n", pppppAge[0][0][0]);
- puts("----------------------------");
- printf("**pppppAge points to address: %p\n", **pppppAge);
- printf("*pppppAge[0] points to address: %p\n", *pppppAge[0]);
- printf("pppppAge[0][0] points to address: %p\n", pppppAge[0][0]);
- puts("----------------------------");
- printf("*pppppAge points to address: %p\n", *pppppAge);
- printf("pppppAge[0] points to address: %p\n", pppppAge[0]);
- printf("pppppAge points to address: %p\n", pppppAge);
- printf("Actual address of pppppAge: %p\n", &pppppAge);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement