Pointer to Pointer in C
Level 5279 keystrokes
Creates a pointer to an int and a pointer to that pointer, reads 100 through one and two levels of indirection, then changes the value to 200 through **pptr. It also prints the address held in ptr twice, once via *pptr; the address differs from run to run.
C code
// The int that both pointers lead to1int value = 100;// ptr holds the address of value2int *ptr = &value;// pptr holds the address of ptr: a pointer to a pointer3int **pptr = &ptr;4 // Reads the variable directly: prints Value: 1005printf("Value: %d\n", value);// One dereference follows ptr to value: prints *ptr: 1006printf("*ptr: %d\n", *ptr);// Two dereferences: pptr → ptr → value, prints **pptr: 1007printf("**pptr: %d\n", **pptr);8 // Writes through both levels, so value itself becomes 2009**pptr = 200;// Prints After change: 20010printf("After change: %d\n", value);// Prints the address stored in ptr; %p expects void *, and the value differs from run to run11printf("ptr addr: %p\n", (void *)ptr);// *pptr is ptr itself, so the same address is printed12printf("*pptr addr: %p\n", (void *)*pptr);Output
Value: 100 *ptr: 100 **pptr: 100 After change: 200 ptr addr: 0x7fff5fbff8ac *pptr addr: 0x7fff5fbff8ac
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C code and how often they appear.
*× 15"× 12;× 10(× 8)× 8,× 6:× 6\× 6%× 6=× 4