calling sizeof on a function call skips actually calling the function!}
问题 I happened to stumble across this piece of code. int x(int a){ std::cout<<a<<std::endl; return a + 1; } int main() { std::cout<<sizeof(x(20))<<std::endl; return 0; } I expected it to print 20 followed 4. But it just prints 4. Why does it happen so? Isn't it incorrect to optimize out a function, that has a side effect (printing to IO/file etc)? 回答1: sizeof is a compile-time operator, and the operand is never evaluated. 回答2: sizeof is actually an operator and it is evaluated in compile-time.