codegurukool.com · Free coding tutorials & online compiler

Home › C Tutorial › C arrays

C arrays

Many values of one type.

Index starts at 0. C does not check bounds, so stay inside the size. Get the length with sizeof(a)/sizeof(a[0]).

Example code

#include <stdio.h>
int main() {
  int a[] = {10, 20, 30};
  int n = sizeof(a) / sizeof(a[0]);
  for (int i = 0; i < n; i++) printf("%d ", a[i]);
  printf("\n");
  return 0;
}

Run this code in the online editor

← C break and continueC strings →