C Programming Questions and Answers – Precedence and Order of Evaluation – 2

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Precedence and Order of Evaluation – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

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

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.

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

advertisement
advertisement
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  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
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  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
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  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
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  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
View Answer

Answer: b
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.