Array Access in C++

Level 276 keystrokes

Creates an int array {10, 20, 30} and reads elements by index: nums[0] prints 10 and nums[2] prints 30.

C++ code

// The [] is left empty, so the size 3 is taken from the initializer list
1int nums[] = {10, 20, 30};
// Indexes start at 0, so nums[0] is the first element, 10
2cout << nums[0] << endl;
// nums[2] is the third and last element, 30
3cout << nums[2] << endl;

Output

10
30
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.

  • <× 8
  • ;× 3
  • [× 3
  • ]× 3
  • ,× 2
  • {× 1
  • }× 1
  • =× 1

More C++ examples at level 2

← C++ typing practice