## Please Turn On Java Script To Access This Site.

C Institute | Questions

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
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 --

```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
Correct Answer : c
Explanation : Here unary minus (or negation) operator is used twice. So - -20 results in 20, similarly + +20 results in 20.