Saturday 13 April 2013

Operator's tricky program 10


What will be output of the following program?

#include<stdio.h>
int main(){
    int a;
    a=sizeof(!5.6);
    printf("%d",a);
    return 0;
}

Explanation
Output:
Turbo C++ 3.0: 2
Turbo C ++4.5: 2
Linux GCC: 4
Visual C++: 4

Explanation:
! is negation operator it return either integer 0 or 1.
! Any operand = 0 if operand is non zero.
! Any operand = 1 if operand is zero.
So, !5.6 = 0
Since 0 is integer number and size of integer data type is two byte.

No comments:

Post a Comment