True / False Questions

Question 1 :

If the file to be included doesn't exist, the preprocessor flashes an error message.


A). True
B). False
Answer : Option A

Explanation :

True, the included file does not exist it will generate the error.


Question 2 :

Preprocessor directive #undef can be used only on a macro that has been #define earlier


A). True
B). False
Answer : Option A

Explanation :

True, #undef can be used only on a macro that has been #define earlier
Example: #define PI 3.14
We can undefine PI macro by #undef PI


Question 3 :

There exists a way to prevent the same file from getting #included twice in the same program.


A). True
B). False
Answer : Option A

Explanation :

True, We can prevent the same file from getting included again by using a preprocessor directive called #ifndef (short for "if not defined") to determine whether we've already defined a preprocessor symbol called XSTRING_H. If we have already defined this symbol, the compiler will ignore the rest of the file until it sees a #endif (which in this case is at the end of the file).

#ifndef XSTRING_H

#define XSTRING_H defines the same preprocessor symbol,

Finally, the last line of the file, #endif


Question 4 :

A preprocessor directive is a message from programmer to the preprocessor.


A). True
B). False
Answer : Option A

Explanation :

True, the programmer tells the compiler to include the preprocessor when compiling.


Question 5 :

Macro calls and function calls work exactly similarly.


A). True
B). False
Answer : Option B

Explanation :

False, A macro just replaces each occurrence with the code assigned to it. e.g. SQUARE(3) with ((3)*(3)) in the program.
A function is compiled once and can be called from anywhere that has visibility to the funciton.


Question 6 :

A macro must always be defined in capital letters.


A). True
B). False
Answer : Option B

Explanation :

FALSE, The macro is case insensitive.


Question 7 :

Macros have a local scope.


A). True
B). False
Answer : Option B

Explanation :

False, The scope of macros is globals and functions. Also the scope of macros is only from the point of definition to the end of the file.


Question 8 :

Every C program will contain at least one preprocessor directive.


A). True
B). False
Answer : Option B

Explanation :

False, the preprocessor directive is not mandatory in any c program.


Question 9 :

Preprocessor directive #ifdef .. #else ... #endif is used for conditional compilation.


A). True
B). False
Answer : Option A

Explanation :

True, these macros are used for conditional operation.

#if 
#elif 
#endif


Question 10 :

Macros with arguments are allowed


A). True
B). False
Answer : Option A

Explanation :

True, A macro may have arguments.
Example: #define CUBE(X)(X*X*X)


Question 11 :

In a macro call the control is passed to the macro.


A). True
B). False
Answer : Option B

Explanation :

False, Always the macro is substituted by the given text/expression.


Question 12 :

A header file contains macros, structure declaration and function prototypes.


A). True
B). False
Answer : Option A

Explanation :

True, the header file contains classes, function prototypes, structure declaration, macros.


Question 13 :

The preprocessor can trap simple errors like missing declarations, nested comments or mismatch of braces.


A). True
B). False
Answer : Option B

Explanation :

False, the preprocessor cannot trap the errors, it only replaces the macro with the given expression. But the compiler will detect errors.


Question 14 :

A preprocessor directive is a message from compiler to a linker.


A). True
B). False
Answer : Option B

Explanation :

FALSE

Example: #define symbol replacement

When the preprocessor encounters #define directive, it replaces any occurrence of symbol in the rest of the code by replacement. This replacement can be an statement or expression or a block or simple text.


Question 15 :

Once preprocessing is over and the program is sent for the compilation the macros are removed from the expanded source code.


A). True
B). False
Answer : Option A

Explanation :

True, After preprocessing all the macro in the program are removed.