250+ TOP MCQs on Precedence and Order of Evaluation and Answers

C language Objective Questions on “Precedence and Order of Evaluation”. One shall practice these Objective 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 language Objective Questions come with detailed explanation of the answers which helps in better understanding of C concepts.

Here is a listing of C language Objective Questions “Precedence and Order of Evaluation” along with answers, explanations and/or solutions:

1. What will be the output of the following C function?

  1.     #include 
  2.     int main()
  3.     {
  4.         reverse(1);
  5.     }
  6.     void reverse(int i)
  7.     {
  8.         if (i > 5)
  9.             exit(0);
  10.         printf("%dn", i);
  11.         return reverse(i++);
  12.     }

a) 1 2 3 4 5
b) 1 2 3 4
c) Compile time error
d) Stack overflow
Answer: d
Clarification: None.

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

  1.     #include 
  2.     void reverse(int i);
  3.     int main()
  4.     {
  5.         reverse(1);
  6.     }
  7.     void reverse(int i)
  8.     {
  9.         if (i > 5)
  10.             return ;
  11.         printf("%d ", i);
  12.         return reverse((i++, i));
  13.     }

a) 1 2 3 4 5
b) Segmentation fault
c) Compilation error
d) Undefined behaviour
Answer: a
Clarification: None.

3. In expression i = g() + f(), first function called depends on __________
a) Compiler
b) Associativiy of () operator
c) Precedence of () and + operator
d) Left to write of the expression
Answer: a
Clarification: None.

4. What will be the final values of i and j in the following C code?

  1.     #include 
  2.     int x = 0;
  3.     int main()
  4.     {
  5.         int i = (f() + g()) || g();
  6.         int j = g() || (f() + g());
  7.     }
  8.     int f()
  9.     {
  10.         if (x == 0)
  11.             return x + 1;
  12.         else
  13.             return x - 1;
  14.     }
  15.     int g()
  16.     {
  17.         return x++;
  18.     }

a) i value is 1 and j value is 1
b) i value is 0 and j value is 0
c) i value is 1 and j value is undefined
d) i and j value are undefined
Answer: d
Clarification: None.

5. What will be the final values of i and j in the following C code?

  1.     #include 
  2.     int x = 0;
  3.     int main()
  4.     {
  5.         int i = (f() + g()) | g(); //bitwise or
  6.         int j = g() | (f() + g()); //bitwise or
  7.     }
  8.     int f()
  9.     {
  10.         if (x == 0)
  11.             return x + 1;
  12.         else
  13.             return x - 1;
  14.     }
  15.     int g()
  16.     {
  17.         return x++;
  18.     }

a) i value is 1 and j value is 1
b) i value is 0 and j value is 0
c) i value is 1 and j value is undefined
d) i and j value are undefined
Answer: c
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 0;
  5.         int z = y && (y |= 10);
  6.         printf("%dn", z);
  7.         return 0;
  8.     }

a) 1
b) 0
c) Undefined behaviour due to order of evaluation
d) 2
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 0;
  5.         int z = (y++) ? 2 : y == 1 && x;
  6.         printf("%dn", z);
  7.         return 0;
  8.     }

a) 0
b) 1
c) 2
d) Undefined behaviour
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 0;
  5.         int z;
  6.         z = (y++, y);
  7.         printf("%dn", z);
  8.         return 0;
  9.     }

a) 0
b) 1
c) Undefined behaviour
d) Compilation error
Answer: b
Clarification: None.

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

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 0, l;
  5.         int z;
  6.         z = y = 1, l = x && y;
  7.         printf("%dn", l);
  8.         return 0;
  9.     }

a) 0
b) 1
c) Undefined behaviour due to order of evaluation can be different
d) Compilation error
Answer: b
Clarification: None.

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

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

a) 12
b) 20
c) 4
d) Either 12 or 20
Answer: b
Clarification: None.

  250+ TOP MCQs on Relational & Logical Operators and Answers

Leave a Comment

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

Scroll to Top