Question: What will be output when you will execute following c code?#include<stdio.h>
int main(){
double num=5.2;
int var=5;
printf("%d\t",sizeof(!num));
printf("%d\t",sizeof(var=15/2));
printf("%d",var);
return 0;
}
Choose all that apply:
A
B
C
D
E
4 2 7
B
4 4 5
C
2 2 5
D
2 4 7
E
8 2 7
Note: Turbo C++ 3.0: 2 2 5
Turbo C ++4.5: 2 2 5
Linux GCC: 4 4 5
Visual C++: 4 4 5
sizeof(Expr) operator always returns the an integer value which represents the size of the final value of the expression expr.
Consider on the following expression:
!num
=!5.2
=0
0 is int type integer constant and it size is 2 by in TURBO C 3.0 compiler and 4 in the TURBO C 4.5 and Linux GCC compilers.
Consider on the following expression:
var = 15/2
=> var = 7
=> 7
7 is int type integer constant.
Any expression which is evaluated inside the sizeof operator its scope always will be within the sizeof operator. So value of variable var will remain 5 in the printf statement.