Single Choice Not Set

QWhat will the the output of the following program?

#include "stdio.h"

int main() 

{ 

  int x, y = 5, z = 5; 

  x = y == z; 

  printf("%d", x); 

  

  getchar(); 

  return 0; 

}

ID: #4164 Operators and Enums in C Language 399 views
Question Info
#4164Q ID
Not SetDifficulty
Operators and Enums in C LanguageTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 00
  • B 1
  • C 5
  • D Compilation error
Correct Answer

Explanation

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.

Share This Question

Challenge a friend or share with your study group.