LOGBOOK

HELP

Quiz Entry - updated: 2026.07.10

Why does sizeof not evaluate its argument?

sizeof only needs the type of its operand, which the compiler knows at compile time — so it computes the size without ever running the expression (the exception is variable-length arrays).

int x = 5;
// x is still 5!
size_t s = sizeof(x++);
// sizeof only looks at the TYPE, doesn't run x++

This is safe:

int *p = NULL;
// OK! Doesn't actually dereference NULL
size_t s = sizeof(*p);
// Just determines size of int

Array vs pointer gotcha:

int arr[10];
int *p = arr;

// 40 (10 × 4 bytes) - size of array
sizeof(arr)
// 8 (on 64-bit) - size of pointer!
sizeof(p)

void foo(int arr[]) {
    // 8! Arrays decay to pointers in function params
    sizeof(arr);
}

Parentheses are optional for variables:

// OK
sizeof x
// Also OK
sizeof(x)
// Parentheses required for types
sizeof(int)
// ERROR!
sizeof int

Go deeper:

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