Skip to content
Related Articles
Open in App
Not now

Related Articles

C | Operators | Question 1

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 08 May, 2017
Improve Article
Save Article
#include \"stdio.h\"

int main() 


  int x, y = 5, z = 5; 

  x = y == z; 

  printf(\"%d\", x); 



  return 0; 









Compiler Error

Answer: (B)


The crux of the question lies in the statement x = y==z. The operator == is executed before = because precedence of comparison operators (<=, >= and ==) is higher than assignment operator =. 
The result of a comparison operator is either 0 or 1 based on the comparison result. Since y is equal to z, value of the expression y == z becomes 1 and the value is assigned to x via the assignment operator.

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!