C Programming Questions and Answers on Precedence and Order of Evaluation for Freshers

1. What is the output of this C code?
  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("%d\n", 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
2. What is the output of this C code?
  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
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

4. What is the value of i and j in the below 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
5. What is the value of i and j in the below 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
6. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 0;
  5.         int z = y && (y |= 10);
  6.         printf("%d\n", z);
  7.         return 0;
  8.     }
a) 1
b) 0
c) Undefined behaviour due to order of evaluation
d) 2
Answer: b
7. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 0;
  5.         int z = (y++) ? 2 : y == 1 && x;
  6.         printf("%d\n", z);
  7.         return 0;
  8.     }
a) 0
b) 1
c) 2
d) Undefined behaviour
Answer: b
8. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 0;
  5.         int z;
  6.         z = (y++, y);
  7.         printf("%d\n", z);
  8.         return 0;
  9.     }
a) 0
b) 1
c) Undefined behaviour
d) Compilation error
Answer: b
9. What is the output of this 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("%d\n", 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
10. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int y = 2;
  5.         int z = y +(y = 10);
  6.         printf("%d\n", z);
  7.     }
a) 12
b) 20
c) 4
d) Either 12 or 20
Answer: b
11. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 2;
  5.         float f = y + x /= x / y;
  6.         printf("%d %f\n", x, f);
  7.         return 0;
  8.     }
a) 2 4.000000
b) Compile time error
c) 2 3.500000
d) Undefined behaviour
Answer: b
12. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 1, y = 2;
  5.         if (x && y == 1)
  6.             printf("true\n");
  7.         else
  8.             printf("false\n");
  9.     }
a) true
b) false
c) compile time error
d) undefined behaviour
Answer: b
13. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 1, y = 2;
  5.         int z = x & y == 2;
  6.         printf("%d\n", z);
  7.     }
a) 0
b) 1
c) Compile time error
d) Undefined behaviour
Answer: b
14. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 3, y = 2;
  5.         int z = x /= y %= 2;
  6.         printf("%d\n", z);
  7.     }
a) 1
b) Compile time error
c) Floating point exception
d) Segmentation fault
Answer: c
15. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 3, y = 2;
  5.         int z = x << 1 > 5;
  6.         printf("%d\n", z);
  7.     }
a) 1
b) 0
c) 3
d) Compile time error
Answer: a
16. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 3; //, y = 2;
  5.         const int *p = &x;
  6.         *p++;
  7.         printf("%d\n", *p);
  8.     }
a) Increment of read-only location compile error
b) 4
c) Some garbage value
d) Undefined behaviour
Answer: c
17. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 2;
  5.         int z = x ^ y & 1;
  6.         printf("%d\n", z);
  7.     }
a) 1
b) 2
c) 0
d) 1 or 2
Answer: b
18. What is the output of this C code?
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 2, y = 0;
  5.         int z = x && y = 1;
  6.         printf("%d\n", z);
  7.     }
a) 0
b) 1
c) Compile time error
d) 2
Answer: c
.
19. What is the output of the code given below
  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 0, y = 2;
  5.         if (!x && y)
  6.             printf("true\n");
  7.         else
  8.             printf("false\n");
  9.     }
a) true
b) false
c) compile time error
d) undefined behaviour
Answer: a
20. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 0, y = 2;
  5.         int z = ~x & y;
  6.         printf("%d\n", z);
  7.     }
a) -1
b) 2
c) 0
d) Compile time error
Answer: b
21. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int a = 5 * 3 + 2 - 4;
  5.         printf("%d", a);
  6.     }
a) 13
b) 14
c) 12
d) 1 6
Answer: a
22. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int a = 2 + 4 + 3 * 5 / 3 - 5;
  5.         printf("%d", a);
  6.     }
a) 7
b) 6
c) 10
d) 9
Answer: b
23. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int a = 5 * 3 % 6 - 8 + 3;
  5.         printf("%d", a);
  6.     }
a) 10
b) 2
c) -2
d) -3
Answer: c
24. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int b = 6;
  5.         int c = 7;
  6.         int a = ++b + c--;
  7.         printf("%d", a);
  8.     }
a) Run time error
b) 15
c) 13
d) 14
Answer: d
25. What is the output of this C code?
  1.     #include 
  2.     void main(
  3.     {
  4.         double b = 8;
  5.         b++;
  6.         printf("%lf", b);
  7.     }
a) 9.000000
b) 9
c) 9.0
d) Run time error
Answer: a
26. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         double b = 3 % 0 * 1 - 4 / 2;
  5.         printf("%lf", b);
  6.     }
a) -2
b) Floating point Exception
c) 1
d) None of the mentioned
Answer: b
27. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         double b = 5 % 3 & 4 + 5 * 6;
  5.         printf("%lf", b);
  6.     }
a) 2
b) 30
c) 2.000000
d) Run time error
Answer: c
28. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         double b = 3 && 5 & 4 % 3;
  5.         printf("%lf", b);
  6.     }
a) 3.000000
b) 4.000000
c) 5.000000
d) 1.000000
Answer: d
.
29. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         double b = 5 & 3 && 4 || 5 | 6;
  5.         printf("%lf", b);
  6.     }
a) 1.000000
b) 0.000000
c) 7.000000
d) 2.000000
Answer: a
30. What is the output of this C code?
  1.     #include 
  2.     void main()
  3.     {
  4.         int k = 0;
  5.         double b = k++ + ++k + k--;
  6.         printf("%d", k);
  7.     }
a) 6
b) 1
c) 5
d) undefined
Answer: d

Related

HTML Multiple Choice Questions & Answers on HTML5’s Open Media Effort for Freshers

1. __________ can be used to advise the browser to download media content in the background to improve playback. a) posterb) autobufferc) bufferd) data-X Answer: b Explanation: It suggests to the...

CSS Multiple Choice Questions & Answers on Embedding Web Fonts for Freshers

1.Which of the following is used to associate a font name to be used in a style sheet with somedownloadable font? a) @font-faceb) @charsetc) @mediad) !important Answer: a 2. Which of the followin...

C Programming Questions and Answers on External Variables for Freshers

1. What is the output of this C code? #include void main() { m(); printf("%d", x); } int x; void m() { x = 4; } ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item