#include "stdio.h"
int main()
{
int x, y = 5, z = 5;
x = y == z;
printf("%d", x);
getchar();
return 0;
}
(A) 0
(B) 1
(C) 5
(D) Compiler Error
Answer: (B)
|
|
chevron_right
filter_none
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.
Recommended Posts:
- C | Operators | Question 2
- C | Operators | Question 3
- C | Operators | Question 4
- C | Operators | Question 5
- C | Operators | Question 6
- C | Operators | Question 7
- C | Operators | Question 8
- C | Operators | Question 9
- C | Operators | Question 10
- C | Operators | Question 11
- C | Operators | Question 12
- C | Operators | Question 13
- C | Operators | Question 27
- C | Operators | Question 15
- C | Operators | Question 16
- C | Operators | Question 17
- C | Operators | Question 18
- C | Operators | Question 26
- C | Operators | Question 27
- C | Operators | Question 21

