Pointer to Pointer in C

Level 3103 keystrokes

Uses a pointer to a pointer (double pointer) to reach a value. The printed address differs between runs and machines.

C code

// The value at the end of the chain
1int val = 100;
// p holds the address of val
2int *p = &val;
// int ** is a pointer to an int pointer; pp holds the address of p
3int **pp = &p;
// **pp follows two steps, pp → p → val, and reads 100
4printf("Value: %d\n", **pp);
// *pp is p itself, the address of val; its value changes from run to run
5printf("Address: %p\n", *pp);

Output

Value: 100
Address: 0x7ffd5e8c3a4c
Practice typing this code

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.

  • *× 6
  • ;× 5
  • "× 4
  • =× 3
  • ,× 2
  • :× 2
  • (× 2
  • )× 2
  • \× 2
  • &× 2

More C examples at level 3

← C typing practice