C Programming Questions and Answers – Conditional Inclusion
C Programming Questions and Answers – Conditional Inclusion
1.What is the output of this C code?
#include <stdio.h>
#define SYSTEM 20
int main()
{
int a = 20;
#if SYSTEM == a
printf(“HELLO “);
#endif
#if SYSTEM == 20
printf(“WORLD\n”);
#endif
}
a) HELLO
b) WORLD
c) HELLO WORLD
d) No Output
View Answer
2.Comment on the following code?
#include <stdio.h>
#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
View Answer
3.The “else if” in conditional inclusion is written by?
a) #else if
b) #elseif
c) #elsif
d) #elif
View Answer
4.What is the output of this C code?
#include <stdio.h>
#define COLD
int main()
{
#ifdef COLD
printf(“COLD\t”);
#undef COLD
#endif
#ifdef COLD
printf(“HOT\t”);
#endif
}
a) HOT
b) COLD
c) COLD HOT
d) No Output
View Answer
5.Which of the following sequences are unaccepted in C language?
a) #if
#else
#endif
b) #if
#elif
#endif
c) #if
#if
#endif
d) #if
#undef
#endif
View Answer
6.In a conditional inclusion, if the condition that comes after the if holds.
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) Both a & b
d) None of the mentioned
View Answer
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
View Answer
8.The #elif directive cannot appear after the preprocessor #else directive.
a) true
b) false
c) None of the mentioned
d) Varies
View Answer
9.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
10.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
11.What is the output of this 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
12.What is the output of this 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
13.What is the output of this 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
14.What is the output of this 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
15.What is the output of this 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) Both b and c
d) Preprocessor error
View Answer
16.What is the output of code given below?
#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