Modify via Pointer in C

Level 396 keystrokes

Modifies a variable's value through a pointer using the dereference operator.

C code

// num starts at 5
1int num = 5;
// p holds the address of num
2int *p = #
// Writing through *p changes num itself, without using the name num
3*p = 20;
// num is now 20, not 5 (despite the label "Original")
4printf("Original: %d\n", num);
// *p reads the same memory, so it also shows 20
5printf("Via ptr: %d\n", *p);

Output

Original: 20
Via ptr: 20
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.

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

More C examples at level 3

← C typing practice