Multiple Choice Questions and Answers for Increment and Decrement Operators in C Language

Online C test focuses 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.


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
2. What is the output of this 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
3. What is the output of this 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)
View Answer
Answer:d
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
5. What is the output of this 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
6. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         int j = i++ + i;
  6.         printf("%d\n", j);
  7.     }
a) 0
b) 1
c) 2
d) Compile time error
Answer:a
7. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 2;
  5.         int j = ++i + i;
  6.         printf("%d\n", j);
  7.     }
a) 6
b) 5
c) 4
d) Compile time error
Answer:a
8. Comment on the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 2;
  5.         int i = i++ + i;
  6.         printf("%d\n", 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) Both a and b
Answer:a
9. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 0;
  5.         int x = i++, y = ++i;
  6.         printf("%d % d\n", x, y);
  7.         return 0;
  8.     }
a) 0, 2
b) 0, 1
c) 1, 2
d) Undefined
Answer:a 
10. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int i = 10;
  5.         int *p = &i;
  6.         printf("%d\n", *p++);
  7.     }
a) 10
b) 11
c) Garbage value
d) Address of i
Answer:a 
11. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 97;
  5.         int y = sizeof(x++);
  6.         printf("X is %d", x);
  7.     }
a) X is 97
b) X is 98
c) X is 99
d) Run time error
Answer:a 
12. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 4, y, z;
  5.         y = --x;
  6.         z = x--;
  7.         printf("%d%d%d", x,  y, z);
  8.     }
a) 3 2 3
b) 2 3 3
c) 3 2 2
d) 2 3 4
Answer:b 
13. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int x = 4;
  5.         int *p = &x;
  6.         int *k = p++;
  7.         int r = p - k;
  8.         printf("%d", r);
  9.     }
a) 4
b) 8
c) 1
d) Run time error
Answer:c 
14. What is the output of this C code?
  1.  #include 
  2.     void main()
  3.     {
  4.         int a = 5, b = -7, c = 0, d;
  5.         d = ++a && ++b || ++c;
  6.         printf("\n%d%d%d%d", a,  b, c, d);
  7.     }
a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
Answer:d 
15. What is the output of this C code?
  1.  #include 
  2.     void main()
  3.     {
  4.         int a = -5;
  5.         int k = (a++, ++a);
  6.         printf("%d\n", k);
  7.     }
a) -4
b) -5
c) 4
d) -3
Answer:d

Related

Multiple Choice Questions 2699603746803648465

Post a Comment

emo-but-icon

item