250+ TOP MCQs on Increment and Decrement Operators and Answers

online C test on “Increment and Decrement Operators”. One shall practice these test questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C online test questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of online C test questions on “Increment and Decrement Operators” along with answers, explanations and/or solutions:

1. What is the difference between the following 2 codes?

  1.     #include  //Program 1
  2.     int main()
  3.     {
  4.         int d, a = 1, b = 2;
  5.         d =  a++ + ++b;
  6.         printf("%d %d %d", d, a, b);
  7.     }
  1.     #include  //Program 2
  2.     int main()
  3.     {
  4.         int d, a = 1, b = 2;
  5.         d =  a++ +++b;
  6.         printf("%d %d %d", d, a, b);
  7.     }

a) No difference as space doesn’t make any difference, values of a, b, d are same in both the case
b) Space does make a difference, values of a, b, d are different
c) Program 1 has syntax error, program 2 is not
d) Program 2 has syntax error, program 1 is not
Answer: d
Clarification: None.

2. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 1, b = 1, c;
  5.         c = a++ + b;
  6.         printf("%d, %d", a, b);
  7.     }

a) a = 1, b = 1
b) a = 2, b = 1
c) a = 1, b = 2
d) a = 2, b = 2
Answer: b
Clarification: None.

3. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 1, b = 1, d = 1;
  5.         printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d + d++ + a++);
  6.     }

a) 15, 4, 5
b) 9, 6, 9
c) 9, 3, 5
d) Undefined (Compiler Dependent)
Answer: d
Clarification: None.

4. For which of the following, “PI++;” code will fail?
a) #define PI 3.14
b) char *PI = “A”;
c) float PI = 3.14;
d) none of the Mentioned
Answer: a
Clarification: None.

5. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = 10, b = 10;
  5.         if (a = 5)
  6.         b--;
  7.         printf("%d, %d", a, b--);
  8.     }

a) a = 10, b = 9
b) a = 10, b = 8
c) a = 5, b = 9
d) a = 5, b = 8
Answer: c
Clarification: None.

6. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         int j = i++ + i;
  6.         printf("%dn", j);
  7.     }

a) 0
b) 1
c) 2
d) Compile time error
Answer: b
Clarification: None.

7. What will be the output of the following C code?

  1.      #include 
  2.     int main()
  3.     {
  4.         int i = 2;
  5.         int j = ++i + i;
  6.         printf("%dn", j);
  7.     }

a) 6
b) 5
c) 4
d) Compile time error
Answer: a
Clarification: None.

8. What will be the output of the following C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 2;
  5.         int i = i++ + i;
  6.         printf("%dn", i);
  7.     }

a) = operator is not a sequence point
b) ++ operator may return value with or without side effects
c) it can be evaluated as (i++)+i or i+(++i)
d) = operator is a sequence point
Answer: a
Clarification: None.

Leave a Reply

Your email address will not be published. Required fields are marked *