Variable name and scope 1

Variable name and scope 2

Variable name and scope 3

Arithmetic operator 1

Arithmetic operator 2

Relational Operators - 1

Relational Operators - 2

Logical Operators - 1

Logical Operators - 2

Assignment Operator - 1

Assignment Operator - 2

Increment Decrement Operator - 1

Increment Decrement Operator - 2

Conditional Operator - 1

Conditional Operator - 2

sizeof operator - 1

sizeof operator - 2

Bitwise operator - 1

Bitwise operator - 2

Operator precedence and associativity - 1

Operator precedence and associativity - 2

Operator precedence and associativity - 3

if statement - 1

if statement - 2

if else - 1

if else - 2

switch statement - 1

switch statement - 2

for loop - 1

for loop - 2

Previous Topic : Operator precedence and associativity - 1Next Topic : Operator precedence and associativity - 3

This section focuses on C interview questions, tricky questions, and puzzles, and viva questions based on “operator precedence and associativity”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walk-in interviews, viva exams and company interviews), placements, entrance exams and other competitive exams. These programming questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate, engineering student, bca student, mca student, mcs students or an experienced IT professional. It will improve their understanding of C Language. Here is a listing of C questions and puzzles on “operator precedence and associativity” along with answers and/or explanations.

Q1:What will be the output? #include <stdio.h> int main() { printf("%d", 1 << 2 + 3 << 4); return 0; }

a) 52

b) 512

c) 212

d) 0

b) 512

c) 212

d) 0

Correct Answer : b

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 is solved as 1 << (2 + 3) << 4 which in turn reduces to (1 << 5) << 4 as the shift operator has left-to-right associativity.

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 is solved as 1 << (2 + 3) << 4 which in turn reduces to (1 << 5) << 4 as the shift operator has left-to-right associativity.

Previous Topic : Operator precedence and associativity - 1Next Topic : Operator precedence and associativity - 3