# C PROGRAMS
C Quiz
➤ Identifiers & Data Types Quiz
➤ Octal Decimal & Hexadecimal
➤ Increment-Decrement Quiz
➤ Relational-Logical Quiz
➤ Arithmetic -Assignment Quiz
➤ Comma Operator Quiz
➤ Sizeof operator Quiz
➤ printf() Quiz Set-1
➤ printf() Quiz Set-2
➤ printf() Quiz Set-3
➤ printf() Quiz Set-4
➤ If statement Quiz in C
➤ If-else statement Quiz
Quiz on Increment and Decrement Operators in C | Increment and decrement operators are also known as unary operators’ because they operate on a single operand. The increment operator (++) adds 1 to its operand and decrement operator (--
) subtracts one.
Operator | Meaning |
++ | Increment Operator |
– – | Decrement Operator |
Syntax:-
++variable;
// pre-increment operatorvariable++;
//post-increment operator--variable;
// pre-decrement operatorvariable--;
// post-decrement operator
If you finding difficulties to solve these questions then first you should learn these:- Operators in C, Bitwise operators in C
C Quiz on Increment and Decrement
Q1) What will be the output of the below C program?
#include<stdio.h>
int main()
{
int x, y;
x = 5;
y = x++ / 2;
printf("%d", y);
return 0;
}
a) 3
b) Compile-time error
c) None of these
d) 2
View Answer
Answer:- d) 2The given expression is:- y=x++ / 2; x++ so post-increment, y=5/2=2. Hence, x=6 and y=2.
Q2) What will be the output of the below C program?
#include<stdio.h>
int main()
{
int a=4,b,c;
b = --a;
c = a--;
printf("%d %d %d",a,b,c);
return 0;
}
a) 3 3 2
b) 2 3 2
c) 3 2 2
d) 2 3 3
View Answer
Answer:- d) 2 3 3The first expression is b=–a; so, a becomes 3 (a=3) and b=3. Now, c=a–; so, c=3 and a=2. Finally, a=2, b=3 and c=3.
Q3) What will be the output of the below C program?
#include<stdio.h>
int main()
{
int a=5;
printf("%d", ++a++);
return 0;
}
a) 6
b) 5
c) Compile-time error
d) 7
View Answer
Answer:- c) Compile-time errorCompile time error: lvalue required as increment operand
Q4) What will be the output of the below C program?
#include<stdio.h>
int main()
{
int a=3, b=9;
printf("%d ", ++(a*b+1));
return 0;
}
a) Compile-time error
b) 29
c) 28
d) None of these
View Answer
Answer:- a) Compile-time errorError: lvalue required as increment operand; The operand of increment and decrement operators must be a variable, not a constant or expression.
Q5) What will be the output of the below C program?
#include<stdio.h>
int main()
{
int a=10, b=10,c;
c= a+++++b;
printf("%d %d %d",a,b,c);
return 0;
}
a) 21 10 10
b) Compile-time error
c) 21 10 11
d) 21 11 11
View Answer
Answer:- b) Compile-time errorCompile time error: lvalue required as increment operand
c=a+++++b;
^~
Q6) What will be the output of the below C program?
#include<stdio.h>
int main()
{
int a=2,b=1,c=0;
c = a +++ b;
printf("%d %d %d",a,b,c);
return 0;
}
a) 3 1 3
b) Compile-time error
c) 2 2 4
d) None of these
View Answer
Answer:- a) 3 1 3The expression c=a+++b; is treated as c=(a++)+b; so, a=3, b=1, c=3
Q7) What will be the output of the below C program?
#include<stdio.h>
int main()
{
int x;
x = 5;
printf("%d ", x);
printf("%d ", x--);
printf("%d", x);
return 0;
}
a) 5 4 4
b) 5 5 4
c) 5 4 3
d) 5 5 5
View Answer
Answer:- b) 5 5 4Q8) What will be the output of the below C program?
#include<stdio.h>
int main()
{
int a=10, b;
b = ++++a;
printf("%d %d",a,b );
return 0;
}
a) Compile-time error
b) 10
c) 12
d) 11
View Answer
Answer:- a) Compile-time errorCompile time error: lvalue required as increment operand
b=++++a;
^~
Q9) What will be the output of the below C program?
#include<stdio.h>
int main()
{
printf("%d ", + +9);
printf("%d ", + -9);
printf("%d ", - +9);
printf("%d ", - -9);
return 0;
}
a) 9 -9 -9 9
b) 10 9 9 9
c) 10 -9 -9 8
d) 10 9 9 8
View Answer
Answer:- a) 9 -9 -9 9These are not increment or decrement operators.
Q10) What will be the output of the below C program?
#include<stdio.h>
int main()
{
int x, y;
x = 5;
y = x++;
printf("%d ",x);
printf("%d",y);
return 0;
}
a) 5 5
b) 6 6
c) 6 5
d) 5 6
View Answer
Answer:- c) 6 5x=5 and y=x++; from y=x++, it is postfix increment so first value of x copies to variable y and now the value of x incremented by 1. Hence y=5 and x=6.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!
Enjoyed a lot answering with my homie.
I enjoyed this very much, better than others.
Very Informative.
Thanks for your valuable content.