sizeof Operator

suggest change

With a type as operand

Yields the size in bytes, as a size_t, of an object of the given type. A type operand requires parentheses. The size of char is always 1. The size of other types is implementation-defined. sizeof itself does not evaluate a type.

printf("%zu\n", sizeof(int)); /* Valid, outputs the size of an int object, which is platform-dependent. */
printf("%zu\n", sizeof int); /* Invalid, types as arguments need to be surrounded by parentheses! */

With an expression as operand

Yields the size in bytes of an object of the expression’s type. The operand is not evaluated, except when it has a variable-length array type: the size of a VLA is computed at run time, and that evaluation can have side effects. Parentheses are not required around an expression. They are still worth using, because sizeof binds more tightly than most operators: sizeof x + y is (sizeof x) + y, not sizeof (x + y).

char ch = 'a';
printf("%zu\n", sizeof(ch)); /* Valid, will output the size of a char object, which is always 1 for all platforms. */
printf("%zu\n", sizeof ch);  /* Valid, will output the size of a char object, which is always 1 for all platforms. */

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents