What is size for the sizeof operator in c?
In recent I was attend one Interview on "SureSoft Technology"...... In that interview, they ask one question lik "What is size for the sizeof operator in c? "
If any one Know answer Share with me?开发者_JS百科
The sizeof
operator itself has no size. Its result will generally* turn into a constant value at compile time.
As for the value it returns, that would be the size, in bytes, of the argument. The type of the result is size_t
(defined in <stdlib.h>
) (§6.5.3.4.4)
* - with the notable exception of dynamically-sized automatic arrays.
You'll find the answers here and here: the result of sizeof is of type size_t, and:
"The actual type of size_t is platform-dependent; a common mistake is to assume size_t is the same as unsigned int, which can lead to programming errors when moving from 32 to 64-bit architecture, for example. According to the 1999 ISO C standard (C99), size_t is an unsigned integer type of at least 16 bits."
The type size_t defined in stddef.h.
The answer is simple - it's the size in bytes of the given data structure that you pass to sizeof.
For example:
sizeof(char) // one bytes
sizeof(int) // four bytes
Hope that helps.
精彩评论