calling sizeof on a function call skips actually calling the function!}

北城以北 提交于 2019-12-01 16:54:21

sizeof is a compile-time operator, and the operand is never evaluated.

sizeof is actually an operator and it is evaluated in compile-time.

The compiler can evaluate it because the size of the return type of x is fixed; it cannot change during program execution.

result of sizeof is computed in compiling time in C++. so there has of function call to x(20)

sizeof() gives the size of the datatype. In your case it doesn't need to call the function to obtain the datatype.

I suspect sizeof also does it's business at compile time rather than runtime...

Let me quote c++03 standard, #5.3.3.

The sizeof operator yields the number of bytes in the object representation of its operand. The operand is either an expression, which is not evaluated, or a parenthesized type-id.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!