+4

How does the sizeof operator works?

Please explain why the output of below code is showing s=4 and x=10? void main{ int x=10, s=0; s=sizeof(x=x+20); cout<<s<<" "<<x; }

3/21/2019 7:14:10 PM

Swati Tripathi

2 Answers

New Answer

+2

"x = x + 20" is an expression of type int, so it is 4 bytes. sizeof gets replaced by a constant at compile-time, so the code itself is never executed.

+2

Tulika Always remember that sizeof operator works on types not on type values