LOGBOOK

HELP

Quiz Entry - updated: 2026.07.10

How do arrays work in C, and why are they "really just pointers"?

An array is just a block of contiguous elements, and a[i] is pure syntactic sugar for *(a + i) — C "doesn't really know" arrays, only pointers.

// Array of 10 ints
int a[10];
// Set second element
a[1] = 5;

// 2D array
int pixel[1024][768];
pixel[0][0] = red;

Arrays ARE pointers:

int a[10];
// Array name IS the address of first element
int *p = a;

// These are IDENTICAL:
a[1] = 5;
// Pointer arithmetic
*(a + 1) = 5;

// In fact, even this works:
// Because a[1] == *(a+1) == *(1+a) == 1[a]
1[a] = 5;

No bounds checking!

int a[10];
// Compiles fine! Undefined behavior at runtime.
a[100] = 5;
// Also "works" - accesses memory before array
a[-1] = 5;

Function parameters - arrays decay to pointers:

// These are
void foo(int *a, int b[]);
// ALL identical!
void foo(int a[], int *b);

// These are
int main(int argc, char **argv);
// equivalent!
int main(int argc, char *argv[]);

Security implication: Buffer overflows happen because C doesn't check array bounds!

From Quiz: REVE1 / C Programming | Updated: Jul 10, 2026