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.

advertisement

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.
advertisement

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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.