Friday 12 April 2013

Operator's tricky Program 6


What will be output of the following program?

#include<stdio.h>
int main(){
    int a=0,b=10;
    if(a=0){
         printf("true");
    }
    else{
         printf("false");
    }
    return 0;
}

Explanation
Output: 
Turbo C++ 3.0: false

Turbo C ++4.5: false

Linux GCC: false

Visual C++: false


Explanation:
As we know = is assignment operator not relation operator. So, a = 0 means zero will assigned to variable a. In c zero represent false and any non-zero number represents true.
So, if(0) means condition is always false hence else part will execute.

No comments:

Post a Comment