codegurukool.com · Free coding tutorials & online compiler

Home › C++ Tutorial › C++ arrays

C++ arrays

Fixed-size lists.

Index starts at 0, and there is no bounds checking. Use sizeof(a)/sizeof(a[0]) for the length.

Example code

#include <iostream>
using namespace std;
int main() {
  int a[3] = {5, 6, 7};
  a[1] = 60;
  int n = sizeof(a) / sizeof(a[0]);
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  cout << endl;
  return 0;
}

Run this code in the online editor

← C++ break and continueC++ structures and enums →