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

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

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

1. What is the type of the following assignment expression if x is of type float and y is of type int?

 y = x + y;

a) int
b) float
c) there is no type for an assignment expression
d) double
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

2. What will be the value of the following C expression?

 (x = foo()) != 1 considering foo() returns 2

a) 2
b) True
c) 1
d) 0
View Answer

Answer: c
Explanation: The C language sub-expression “x = foo()” will assign a value of 2 to the variable ‘x’. Then, it will check if this value is not equal to 1 which is true and hence the result will be 1.
Note: Join free Sanfoundry classes at Telegram or Youtube

3. Operation “a = a * b + a” can also be written as ___________
a) a *= b + 1;
b) (c = a * b)!=(a = c + a);
c) a = (b + 1)* a;
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

4. What will be the final value of c in the following C statement? (Initial value: c = 2)

advertisement
  1. c <<= 1;

a) c = 1;
b) c = 2;
c) c = 3;
d) c = 4;
View Answer

Answer: d
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         int a = 1, b = 2;
  5.         a += b -= a;
  6.         printf("%d %d", a, b);
  7.     }

a) 1 1
b) 1 2
c) 2 1
d) 2 2
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 a = 4, n, i, result = 0;
  5.         scanf("%d", &n);
  6.         for (i = 0;i < n; i++)
  7.         result += a;
  8.     }

a) Addition of a and n
b) Subtraction of a and n
c) Multiplication of a and n
d) Division of a and n
View Answer

Answer: c
Explanation: None.

7. Which of the following is an invalid assignment operator?
a) a %= 10;
b) a /= 10;
c) a |= 10;
d) None of the mentioned
View Answer

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