C Programming Questions and Answers – Conditional Expressions – 2

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Conditional Expressions – 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.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         k < m ? k++ : m = k;
  7.         printf("%d", k);
  8.     }

a) 7
b) 8
c) Compile time error
d) Run time error
View Answer

Answer: c
Explanation: None.
advertisement
advertisement

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

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
  1.     #include <stdio.h>
  2.     void main()
  3.     {
  4.         int k = 8;
  5.         int m = 7;
  6.         k < m ? k = k + 1 : m = m + 1;
  7.         printf("%d", k);
  8.     }

a) Compile time error
b) 9
c) 8
d) Run time error
View Answer

Answer: a
Explanation: None.
advertisement

3. What will be the final values of a and c in the following C statement? (Initial values: a = 2, c = 1)

 c = (c) ? a = 0 : 2;

a) a = 0, c = 0;
b) a = 2, c = 2;
c) a = 2, c = 2;
d) a = 1, c = 2;
View Answer

Answer: a
Explanation: None.
advertisement

4. What will be the data type of the following expression? (Initial data type: a = int, var1 = double, var2 = float)

expression (a < 50)? var1 : var2;

a) int
b) float
c) double
d) Cannot be determined
View Answer

Answer: c
Explanation: None.

5. Which expression has to be present in the following?

exp1 ? exp2 : exp3;

a) exp1
b) exp2
c) exp3
d) all of the mentioned
View Answer

Answer: d
Explanation: None.

6. What will be the final value of c in the following C code snippet? (Initial values: a = 1, b = 2, c = 1)

       c += (-c) ? a : b;

a) Syntax Error
b) c = 1
c) c = 2
d) c = 3
View Answer

Answer: c
Explanation: None.

7. The following C code can be rewritten as _______

c = (n) ? a : b;

a)

    if (!n)c = b;
    else c = a;

b)

    if (n <;= 0)c = b;
    else c = a;

c)

    if (n > 0)c = a;
    else c = b;

d) All of the mentioned
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.

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.