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
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
Explanation: None.
3. What will be the output of the following C code?
#include <stdio.h>
#define MIN 0
#if MIN
#define MAX 10
#endif
int main()
{
printf("%d %d\n", MAX, MIN);
return 0;
}
a) 10 0
b) Compile time error
c) Undefined behaviour
d) None of the mentioned
View Answer
Explanation: None.
4. What will be the output of the following C code?
#include <stdio.h>
#define MIN 0
#ifdef MIN
#define MAX 10
#endif
int main()
{
printf("%d %d\n", MAX, MIN);
return 0;
}
a) 10 0
b) Compile time error
c) Undefined behaviour
d) None of the mentioned
View Answer
Explanation: None.
5. What will be the output of the following C code?
#include <stdio.h>
#define MIN 0
#if defined(MIN) + defined(MAX)
#define MAX 10
#endif
int main()
{
printf("%d %d\n", MAX, MIN);
return 0;
}
a) 10 0
b) Compile time error
c) Undefined behaviour
d) Somegarbagevalue 0
View Answer
Explanation: None.
6. What will be the output of the following C code?
#include <stdio.h>
#define MIN 0
#if defined(MIN) - (!defined(MAX))
#define MAX 10
#endif
int main()
{
printf("%d %d\n", MAX, MIN);
return 0;
}
a) 10 0
b) Compile time error
c) Undefined behaviour
d) Somegarbagevalue 0
View Answer
Explanation: None.
7. What will be the output of the following C code?
#include <stdio.h>
#define MIN 0
#ifdef(MIN)
#define MAX 10
#endif
int main()
{
printf("%d %d\n", MAX, MIN);
return 0;
}
a) 10 0
b) Compile time error
c) Run time error
d) Preprocessor error
View Answer
Explanation: None.
8. What will be the output of the following C code?
#include <stdio.h>
#define MIN 0);
#ifdef MIN
#define MAX 10
#endif
int main()
{
printf("%d %d\n", MAX, MIN
return 0;
}
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
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.
- Practice Computer Science MCQs
- Watch Advanced C Programming Videos
- Check C Books
- Practice BCA MCQs
- Check Computer Science Books