C Programming Questions and Answers – Assignment Operators & Expressions – 1

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Assignment Operators & Expressions – 1”.

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

advertisement

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int x = 0;
  5.         if (x = 0)
  6.             printf("Its zero\n");
  7.         else
  8.             printf("Its not zero\n");
  9.     }

a) Its not zero
b) Its zero
c) Run time error
d) None
View Answer

Answer: a
Explanation: None.
Note: Join free Sanfoundry classes at Telegram or Youtube
advertisement
advertisement

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

advertisement
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int x = 0 == 1 && k++;
  6.         printf("%d%d\n", x, k);
  7.     }

a) 0 9
b) 0 8
c) 1 8
d) 1 9
View Answer

Answer: b
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         char a = 'a';
  5.         int x = (a % 10)++;
  6.         printf("%d\n", x);
  7.     }

a) 6
b) Junk value
c) Compile time error
d) 7
View Answer

Answer: c
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         1 < 2 ? return 1: return 2;
  5.     }

a) returns 1
b) returns 2
c) Varies
d) Compile time error
View Answer

Answer: d
Explanation: None.

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

  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         unsigned int x = -5;
  5.         printf("%d", x);
  6.     }

a) Run time error
b) Aries
c) -5
d) 5
View Answer

Answer: c
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = 2, y = 1;
  5.         x *= x + y;
  6.         printf("%d\n", x);
  7.         return 0;
  8.     }

a) 5
b) 6
c) Undefined behaviour
d) Compile time error
View Answer

Answer: b
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.         x /= x / y;
  6.         printf("%d\n", x);
  7.         return 0;
  8.     }

a) 2
b) 1
c) 0.5
d) Undefined behaviour
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int x = 1, y = 0;
  5.         x &&= y;
  6.         printf("%d\n", x);
  7.     }

a) Compile time error
b) 1
c) 0
d) Undefined behaviour
View Answer

Answer: a
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.

advertisement
advertisement

Leave a Comment

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 & technical discussions at Telegram SanfoundryClasses.