Last Updated: February 25, 2016
·
746
· funkaoshi

sizeof

You can use the sizeof operator in C and C++ to find out the size (in bytes) of a type. For example, if we have defined an array char array[10], then sizeof(array) will return the value 10. sizeof looks like a library function, but it isn’t one, it’s part of the definition of the language itself. The call sizeof array also returns 10. In most cases you can use or drop the parentheses around the operand for sizeof. The one exception to this occurs when trying to determine the size of a type. If a type name is to be the operand for sizeof it must be wrapped in parentheses; if you don’t do this, your program won’t compile. I usually drop the parentheses for calls to sizeof so I can tell at a glance if its operand is a type or a particular variable.