Eroxl's Notes
Dynamic Array

Dynamic arrays in C are arrays whose storage is obtained at runtime via dynamic allocation. A dynamic array variable has a pointer that points to a contiguous block large enough for elements.

Allocation does not set the logical length as you must track the element count yourself. The pointer value is the address of the first element (&arr[0]), and indexing works the same as with fixed-size arrays: arr[i]*(arr + i).

Example

#include <stdlib.h>
#include <stdio.h>

int main(void) {
	size_t n = 10;
	int *arr = malloc(n * sizeof *arr); // arr points to arr[0]
	if (!arr) { perror("malloc"); return 1; }

	arr[0] = 1;
	arr[9] = 42;

	free(arr);
	return 0;
}