Here is a listing of C Objective Questions on “Conditional Inclusion” along with answers, explanations and/or solutions:
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
Answer: d
Clarification: 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
Answer: a
Clarification: None.
3. What will be the output of the following C code?
-
#include -
#define MIN 0 -
#if MIN -
#define MAX 10 -
#endif -
int main()
-
{ -
printf("%d %dn", MAX, MIN);
-
return 0;
-
}
a) 10 0
b) Compile time error
c) Undefined behaviour
d) None of the mentioned
Answer: b
Clarification: None.
4. What will be the output of the following C code?
-
#include -
#define MIN 0 -
#ifdef MIN -
#define MAX 10 -
#endif -
int main()
-
{ -
printf("%d %dn", MAX, MIN);
-
return 0;
-
}
a) 10 0
b) Compile time error
c) Undefined behaviour
d) None of the mentioned
Answer: a
Clarification: None.
5. What will be the output of the following C code?
-
#include -
#define MIN 0 -
#if defined(MIN) + defined(MAX) -
#define MAX 10 -
#endif -
int main()
-
{ -
printf("%d %dn", MAX, MIN);
-
return 0;
-
}
a) 10 0
b) Compile time error
c) Undefined behaviour
d) Somegarbagevalue 0
Answer: a
Clarification: None.
6. What will be the output of the following C code?
-
#include -
#define MIN 0 -
#if defined(MIN) - (!defined(MAX)) -
#define MAX 10 -
#endif -
int main()
-
{ -
printf("%d %dn", MAX, MIN);
-
return 0;
-
}
a) 10 0
b) Compile time error
c) Undefined behaviour
d) Somegarbagevalue 0
Answer: b
Clarification: None.
7. What will be the output of the following C code?
-
#include -
#define MIN 0 -
#ifdef(MIN) -
#define MAX 10 -
#endif -
int main()
-
{ -
printf("%d %dn", MAX, MIN);
-
return 0;
-
}
a) 10 0
b) Compile time error
c) Run time error
d) Preprocessor error
Answer: d
Clarification: None.
8. What will be the output of the following C code?
-
#include -
#define MIN 0); -
#ifdef MIN -
#define MAX 10 -
#endif -
int main()
-
{ -
printf("%d %dn", 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
Answer: a
Clarification: None.
