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

c++, sizeof

Solution

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

Problem

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)?

Original source