Skip to content
Related Articles

Related Articles

Improve Article

C | Operators | Question 16

  • Difficulty Level : Hard
  • Last Updated : 28 Jun, 2021

Predict the output of the below program:




#include <stdio.h>
int main()
{
    printf("%d", 1 << 2 + 3 << 4);
    return 0;
}

(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

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :