C | Operators | Question 16
Predict the output of the below program:
#include <stdio.h> int main() { printf("%d", 1 << 2 + 3 << 4); return 0; } |
chevron_right
filter_none
(A) 112
(B) 52
(C) 512
(D) 0
Answer: (C)
Explanation: The main logic behind the program is the precedence and associativity of the operators. The addition(+) operator has higher precedence than shift(<<) operator. So, the expression boils down to 1 << (2 + 3) << 4 which in turn reduces to (1 << 5) << 4 as the shift operator has left-to-right associativity.
Quiz of this Question
Recommended Posts:
- Operators in C | Set 2 (Relational and Logical Operators)
- C | Operators | Question 4
- C | Operators | Question 26
- C | Operators | Question 27
- C | Operators | Question 21
- C | Operators | Question 3
- C | Operators | Question 2
- C | Operators | Question 17
- C | Operators | Question 18
- C | Operators | Question 27
- C | Operators | Question 13
- C | Operators | Question 12
- C | Operators | Question 11
- C | Operators | Question 10
- C | Operators | Question 22



