c / beginner
Snippet
The sizeof Operator
The sizeof operator is used to determine the size, in bytes, of a variable or a data type on the specific system where the code is running. This is crucial for memory management and understanding how data is stored.
snippet.c
1
2
3
int myInt;printf("Size of int: %zu bytes\n", sizeof(myInt));printf("Size of double: %zu bytes\n", sizeof(double));
Breakdown
1
sizeof(myInt)
Calculates the memory size occupied by the variable myInt.
2
%zu
The specific format specifier used for printing values of type size_t returned by sizeof.