Here is a listing of C Objective Questions on “Conditional Inclusion” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
#define SYSTEM 20
-
int main()
-
{
-
int a = 20;
-
#if SYSTEM == a
-
printf("HELLO ");
-
#endif
-
#if SYSTEM == 20
-
printf("WORLDn");
-
#endif
-
}
a) HELLO
b) WORLD
c) HELLO WORLD
d) No Output
Answer: b
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
#define Cprog
-
int main()
-
{
-
int a = 2;
-
#ifdef Cprog
-
a = 1;
-
printf("%d", Cprog);
-
}
a) No output on execution
b) Output as 1
c) Output as 2
d) Compile time error
Answer: d
Clarification: None.
3. The “else if” in conditional inclusion is written by?
a) #else if
b) #elseif
c) #elsif
d) #elif
Answer: d
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
#define COLD
-
int main()
-
{
-
#ifdef COLD
-
printf("COLDt");
-
#undef COLD
-
#endif
-
#ifdef COLD
-
printf("HOTt");
-
#endif
-
}
a) HOT
b) COLD
c) COLD HOT
d) No Output
Answer: b
Clarification: None.
5. Which of the following sequences are unaccepted in C language?
a)
b)
c)
d)
View Answer
Answer: c
Clarification: 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
Answer: a
Clarification: 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
Answer: d
Clarification: None.
8. The #elif directive cannot appear after the preprocessor #else directive.
a) True
b) False
Answer: a
Clarification: None.