Arrays in C

From the C cheat sheet · Arrays · verified Jul 2026

Arrays

Declaration, iteration, and the pointer relationship.

c
// Quick Reference
int a[5] = {1, 2, 3};   // rest are 0
int n = sizeof(a) / sizeof(a[0]);   // length
int grid[2][3];         // 2D
💡 sizeof(a)/sizeof(a[0]) gives the length - but only before the array decays to a pointer.
⚡ Passing an array to a function passes a pointer; send the length as a separate argument.
📌 C does no bounds checking - writing past the end is undefined behavior (buffer overflow).
🟢 { 0 } zero-initializes the whole array; partial initializers fill the rest with 0.
arrays
Back to the full C cheat sheet