Learn C
#include "arraysstrings/arrays.h"

Arrays in C

#concept

An array is a fixed-size run of same-typed elements laid out contiguously: int scores[5]; reserves five ints back to back. Indexing starts at 0, and a[i] is genuinely pointer arithmetic (address plus i elements) — which is why out-of-bounds access compiles fine and then corrupts memory silently.

Arrays decay to pointers in most expressions (notably function calls), losing their size — always pass the length alongside. Braced initialization (int a[3] = {1,2,3};) fills in order with missing tails zeroed, and int a[] = {1,2,3}; deduces size 3.

#how it works
1

Fixed size, contiguous

int a[5]; reserves five ints adjacently. Stack array sizes must be compile-time constants (except VLAs).

2

Zero-based, unchecked

Valid indexes run 0 to size-1. No bounds checking exists — a[5] on a 5-array reads unrelated memory as undefined behavior.

3

Braced initialization

int a[5] = {1, 2}; sets the first two and zero-fills the rest; int a[] = {1,2,3}; deduces size 3.

4

Decay loses size

Passing an array hands over just a pointer — the callee can't know the length, so pass it as a separate parameter.

#example
#include <stdio.h>
 
int main(void) {
int scores[4] = {90, 80, 70, 60};
int sum = 0;
int i;
for (i = 0; i < 4; ++i) {
sum += scores[i];
}
printf("%.1f\n", sum / 4.0);
return 0;
}
Output
75.0
1The braced list initializes all four elements; sum starts at 0.
2The loop walks indexes 0..3, accumulating 300.
3Dividing by 4.0 keeps floating point — 75.0 prints with one decimal.
#use cases
Fixed-size buffers and lookup tables with zero overhead
Passing arrays plus explicit lengths to processing functions
Zero-filling with partial braced initializers
Recognizing decay whenever an array crosses a function boundary

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in C yourself — building beats watching.