Pointer Increment in C

Level 3101 keystrokes

Uses pointer increment to traverse an array.

C code

// Four values to walk through
1int arr[] = {5, 10, 15, 20};
// p starts at the first element
2int *p = arr;
// arr + 4 is the address just past the last element, so the loop stops there
3while (p < arr + 4) {
// *p++ reads the current value, then moves p to the next element
4 printf("%d ", *p++);
5}
// End the line: 5 10 15 20
6printf("\n");

Output

5 10 15 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.

  • ,× 4
  • ;× 4
  • "× 4
  • (× 3
  • )× 3
  • +× 3
  • {× 2
  • }× 2
  • *× 2
  • =× 2

More C examples at level 3

← C typing practice