Friday 12 April 2013

Operator's tricky Program 4


What will be output of the following program?

#include<stdio.h>
int main(){
    int a=2,b=7,c=10;
    c=a==b;
    printf("%d",c);
    return 0;
}

Explanation
Output: 
Turbo C++ 3.0: 0

Turbo C ++4.5: 0

Linux GCC: 0

Visual C++: 0


Explanation:
== is relational operator which returns only two values.
0: If a == b is false
1: If a == b is true
Since
a=2
b=7
So, a == b is false hence b=0

No comments:

Post a Comment