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

while loop - 1

while loop - 2

do while loop - 1

do while loop - 2

break and continue - 1

break and continue - 2

pointer - 1

This section on C interview questions, tricky questions, and puzzles focuses on “Increment Decrement operator”. 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. Here is a listing of C questions and puzzles on “Increment Decrement operators” along with answers and/or explanations.

Q1:What will be the output of following c code? #include <stdio.h> int main() { int a = 1,b = 1,c,d; c = a || --b; d = a-- && --b; printf("a = %d, b = %d, c = %d, d = %d", a, b, c, d); return 0; }

a) a = 1, b = 1, c = 1, d = 1

b) a = 0, b = 0, c = 0, d = 0

c) a = 0, b = 1, c = 1, d = 0

d) a = 0, b = 0, c = 1, d = 0

b) a = 0, b = 0, c = 0, d = 0

c) a = 0, b = 1, c = 1, d = 0

d) a = 0, b = 0, c = 1, d = 0

Correct Answer : d

Explanation : Initial value of a and b is 1. After expression c=a||--b; c holds 1, a holds 1 and b holds 1, because --b is not executed due to short circuit in logical or operators.

After expression a-- && --b both a and b becomes 0, and d also holds 0.

Learn About ++ and --

Explanation : Initial value of a and b is 1. After expression c=a||--b; c holds 1, a holds 1 and b holds 1, because --b is not executed due to short circuit in logical or operators.

After expression a-- && --b both a and b becomes 0, and d also holds 0.

Learn About ++ and --

Q2:What will be the output of following program ? #include <stdio.h> int main() { int x; x=- -20; printf("x=%d,",x); x=+ +20; printf("x=%d",x); return 0; }

a) Syntax Error

b) x=19,x=21

c) x=20,x=20

d) Runtime Error

b) x=19,x=21

c) x=20,x=20

d) Runtime Error

Correct Answer : c

Explanation : Here unary minus (or negation) operator is used twice. So - -20 results in 20, similarly + +20 results in 20.

Explanation : Here unary minus (or negation) operator is used twice. So - -20 results in 20, similarly + +20 results in 20.