+ 5

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; }

21st Mar 2019, 7:14 PM
Swati Tripathi
Swati Tripathi - avatar
1 Réponse
+ 1
"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.
21st Mar 2019, 7:32 PM
Vlad Serbu
Vlad Serbu - avatar