C Programming Questions and Answers – Conditional Inclusion – 2

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

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

1. For each #if, #ifdef, and #ifndef directive.
a) There are zero or more #elif directives
b) Zero or one #else directive
c) One matching #endif directive
d) All of the mentioned
View Answer

Answer: d
Explanation: None.

2. The #else directive is used for _________
a) Conditionally include source text if the previous #if, #ifdef, #ifndef, or #elif test fails
b) Conditionally include source text if a macro name is not defined
c) Conditionally include source text if a macro name is defined
d) Ending conditional text
View Answer

Answer: a
Explanation: None.
advertisement
advertisement

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

  1.     #include <stdio.h>
  2.     #define MIN 0
  3.     #if MIN
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN);
  9.         return 0;
  10.     }

a) 10 0
b) Compile time error
c) Undefined behaviour
d) None of the mentioned
View Answer

Answer: b
Explanation: None.

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

advertisement
  1.     #include <stdio.h>
  2.     #define MIN 0
  3.     #ifdef MIN
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN);
  9.         return 0;
  10.     }

a) 10 0
b) Compile time error
c) Undefined behaviour
d) None of the mentioned
View Answer

Answer: a
Explanation: None.
advertisement

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

  1.     #include <stdio.h>
  2.     #define MIN 0
  3.     #if defined(MIN) + defined(MAX)
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN);
  9.         return 0;
  10.     }

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

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     #define MIN 0
  3.     #if defined(MIN) - (!defined(MAX))
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN);
  9.         return 0;
  10.     }

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

Answer: b
Explanation: None.

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

  1.     #include <stdio.h>
  2.     #define MIN 0
  3.     #ifdef(MIN)
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN);
  9.         return 0;
  10.     }

a) 10 0
b) Compile time error
c) Run time error
d) Preprocessor error
View Answer

Answer: d
Explanation: None.

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

  1.     #include <stdio.h>
  2.     #define MIN 0);
  3.     #ifdef MIN
  4.     #define MAX 10
  5.     #endif
  6.     int main()
  7.     {
  8.         printf("%d %d\n", MAX, MIN
  9.         return 0;
  10.     }

a) 10 0
b) Compile time error due to illegal syntax for printf
c) Undefined behaviour
d) Compile time error due to illegal MIN value
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.