I happened to stumble over 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 him to print 20, then 4. But he just prints 4. Why is this so? Is it wrong to optimize a function that has a side effect (print to IO / file, etc.)?
Chethan ravindranath
source share