Static arrays are created at compile-time

A static array is created at compile-time, which is why it is called static. Since its size is fixed, you must define it beforehand. Additionally, it cannot be extended or resized at runtime.

#include <stdio.h>

int main(int argc, char**argv) {
	int arr[5];

	arr[0] = 1;
	arr[1] = 2;
	arr[2] = 3;
	arr[3] = 4;
	arr[4] = 5;

	printf("%d\n", arr[0]);

	arr = arr[10]; // Compile error: cannot reassign an array

	return 0;
}

If you don’t know the size beforehand or need to resize the array dynamically, consider using dynamic arrays.

Backlinks: