Machine-translated by Google. Questions are authored in English.
Top

C Preprocessor Questions and Answers

101.

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

Answer: A

Correct answer: True

A directive such as #include or #define is an instruction to the preprocessor - the phase that rewrites the source text before the compiler sees it. It is not part of the C language proper, which is why it has its own syntax and ends at the end of a line rather than at a semicolon.

Please log in or register to report this question.

102.

Macro calls and function calls work exactly similarly.

Answer: B

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.

Please log in or register to report this question.

103.

A macro must always be defined in capital letters.

Answer: B

Correct answer: False

Capitals are a convention, not a requirement. They serve as a warning to the reader that the name will be substituted textually, with all the traps that carries. The preprocessor accepts any valid identifier, and the standard library itself defines lower-case macros such as getchar.

Please log in or register to report this question.

104.

Macros have a local scope.

Answer: B

Correct answer: False

A macro has no scope in the C sense at all. Its definition runs from the #define to the end of the file, or to a matching #undef - braces and functions mean nothing to the preprocessor, which works on text. A #define written inside a function is still in force after that function ends.

Please log in or register to report this question.

105.

Every C program will contain at least one preprocessor directive.

Answer: B

Correct answer: False

Nothing compels a program to use a directive. A program that neither includes a header nor defines a macro - int main(void) { return 0; } - is perfectly valid C. In practice almost every program includes something, but that is habit rather than a rule.

Please log in or register to report this question.

106.

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

Answer: A

Correct answer: True

#ifdef / #else / #endif is exactly the mechanism for conditional compilation: only one branch survives preprocessing, and the other never reaches the compiler at all. It is the usual way of adapting a source file to different platforms or of compiling out debugging code.

Please log in or register to report this question.

107.

Macros with arguments are allowed

Answer: A

Correct answer: True

Function-like macros with parameters are ordinary: #define MAX(a,b) ((a) > (b) ? (a) : (b)). The arguments are substituted as text, which is why the parameters and the whole body need parenthesising and why an argument with a side effect can be evaluated more than once.

Please log in or register to report this question.

108.

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

Answer: B

Correct answer: False

There is no transfer of control. A macro is expanded in place, before compilation, so its body ends up written out at each call site - no jump, no stack frame, no return. That is the essential difference from a function: the speed of inline code, at the cost of size and of type checking.

Please log in or register to report this question.

109.

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

Answer: A

Correct answer: True

A header typically carries exactly those three things - macros, type and structure declarations, and function prototypes - because they are what several source files need to share. What it should not carry is a definition that allocates storage or a function body, since including it in two files would then produce two definitions.

Please log in or register to report this question.

110.

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

Answer: B

Correct answer: False

The preprocessor does not parse C at all. It handles directives, expands macros and strips comments; it has no notion of declarations or of matching braces, so those errors surface later, in the compiler. It does report its own faults, such as a missing include file or an unclosed #if.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: C Preprocessor Questions and Answers || C Preprocessor MCQ Questions and Answers || C Preprocessor GK Questions and Answers || C Preprocessor GK MCQ Questions || C Preprocessor Multiple Choice Questions and Answers || C Preprocessor GK || GK on C Preprocessor || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming