C Programming Questions and Answers – Conditional Inclusion – 1

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Conditional Inclusion – 1”.

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.     #define SYSTEM 20
  3.     int main()
  4.     {
  5.         int a = 20;
  6.         #if SYSTEM == a
  7.         printf("HELLO ");
  8.         #endif
  9.         #if SYSTEM == 20
  10.         printf("WORLD\n");
  11.         #endif
  12.     }

a) HELLO
b) WORLD
c) HELLO WORLD
d) No Output
View Answer

Answer: b
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.     #define Cprog
  3.     int main()
  4.     {
  5.         int a = 2;
  6.         #ifdef Cprog
  7.         a = 1;
  8.         printf("%d", Cprog);
  9.     }

a) No output on execution
b) Output as 1
c) Output as 2
d) Compile time error
View Answer

Answer: d
Explanation: None.
advertisement

3. The “else if” in conditional inclusion is written by?
a) #else if
b) #elseif
c) #elsif
d) #elif
View Answer

Answer: d
Explanation: None.

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

advertisement
  1.     #include <stdio.h>
  2.     #define COLD
  3.     int main()
  4.     {
  5.         #ifdef COLD
  6.         printf("COLD\t");
  7.         #undef COLD
  8.         #endif
  9.         #ifdef COLD
  10.         printf("HOT\t");
  11.         #endif
  12.     }

a) HOT
b) COLD
c) COLD HOT
d) No Output
View Answer

Answer: b
Explanation: None.

5. Which of the following sequences are unaccepted in C language?
a)

   #if
   #else
   #endif

b)

   #if
   #elif
   #endif

c)

   #if
   #if
   #endif

d)

   #if
   #undef
   #endif
View Answer
Answer: c
Explanation: None.
 
 

6. In a conditional inclusion, if the condition that comes after the if is true, then what will happen during compilation?
a) Then the code up to the following #else or #elif or #endif is compiled
b) Then the code up to the following #endif is compiled even if #else or #elif is present
c) Then the code up to the following #eliif is compiled
d) None of the mentioned
View Answer

Answer: a
Explanation: None.

7. Conditional inclusion can be used for ___________
a) Preventing multiple declarations of a variable
b) Check for existence of a variable and doing something if it exists
c) Preventing multiple declarations of same function
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

8. The #elif directive cannot appear after the preprocessor #else directive.
a) True
b) False
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.