Array Element Update in C

Level 281 keystrokes

Changes the second element of the array {1, 2, 3} to 10 and prints all three elements: "1 10 3".

C code

// Creates an int array with 3 elements: 1, 2 and 3
1int arr[] = {1, 2, 3};
// Index 1 is the second element (indices start at 0); its value 2 is replaced by 10
2arr[1] = 10;
// Prints the array after the change: "1 10 3"
3printf("%d %d %d\n", arr[0], arr[1], arr[2]);

Output

1 10 3
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
  • [× 5
  • ]× 5
  • ;× 3
  • %× 3
  • "× 2
  • =× 2
  • (× 1
  • )× 1
  • {× 1

More C examples at level 2

← C typing practice