Created: 2023-01-11 12:31
Status: #concept
Subject: Programming
Tags: C Operator

sizeof Operator

An operator that determines how much bytes does a Constant, Variable, C Data Type, or Expression occupies in memory.

// it is unary and has higher precedence than binary operators
sizeof i + j == (sizeof i) + j

sizeof ( type-name )

This expression evaluates into unsigned Integer representing the number of Bytes (8-bits) required to store a Variable belonging to type-name.

When used on an C Array Identifier, it evaluates to (the # of elements multiplied by the size of a single element).

// idiom to set all elements on an undefined array size to the value 0
for (i = 0; i < sizeof(a) / sizeof(a[0]); i++)
	a[i] = 0;

References