

InterviewSolution
Saved Bookmarks
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
1. |
If the file to be included doesn't exist, the preprocessor flashes an error message. |
Answer» True, the included file does not exist it will generate the error. | |
2. |
Preprocessor directive can be used only on a macro that has been earlier |
Answer» 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 | |
3. |
There exists a way to prevent the same file from getting twice in the same program. |
Answer» 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 | |
4. |
In a macro call the control is passed to the macro. |
Answer» False, Always the macro is substituted by the given text/expression. | |
5. |
A header file contains macros, structure declaration and function prototypes. |
Answer» True, the header file contains classes, function prototypes, structure declaration, macros. | |
6. |
The preprocessor can trap simple errors like missing declarations, nested comments or mismatch of braces. |
Answer» False, the preprocessor cannot trap the errors, it only replaces the macro with the given expression. But the compiler will detect errors. | |
7. |
A preprocessor directive is a message from compiler to a linker. |
Answer» 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. | |
8. |
Once preprocessing is over and the program is sent for the compilation the macros are removed from the expanded source code. |
Answer» True, After preprocessing all the macro in the program are removed. | |
9. |
A macro must always be defined in capital letters. |
Answer» FALSE, The macro is case insensitive. | |
10. |
Will it result in to an error if a header file is included twice? |
Answer» Unless the header file has taken care to ensure that if already included it doesn't get included again. Turbo C, GCC compilers would take care of these problems, generate no error. | |
11. |
Macros have a local scope. |
Answer» 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. | |
12. |
Every C program will contain at least one preprocessor directive. |
Answer» False, the preprocessor directive is not mandatory in any c program. | |
13. |
Preprocessor directive .. ... is used for conditional compilation. |
Answer» True, these macros are used for conditional operation. #if <constant-expression> #elif <constant-expression> #endif | |
14. |
Macros with arguments are allowed |
Answer» True, A macro may have arguments. Example: #define CUBE(X)(X*X*X) | |
15. |
It is necessary that a header files should have a .h extension? |
Answer» No, the header files have any kind of extension. | |
16. |
Will the program compile successfully? |
Answer» Yes, this program will compile and run successfully and prints 20. The macro #ifdef NOTE evaluates the given expression to 1. If satisfied it executes the #ifdef block statements. Here #ifdef condition fails because the Macro NOTE is nowhere declared. Hence the #else block gets executed, the variable a is declared and assigned a value of 20. printf("%d\n", a); It prints the value of variable a 20. | |
17. |
Macro calls and function calls work exactly similarly. |
Answer» 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. | |
18. |
Point out the error in the program |
Answer» The conditional macro #if must have an #endif. In this program there is no #endif statement written. | |
19. |
A preprocessor directive is a message from programmer to the preprocessor. |
Answer» True, the programmer tells the compiler to include the preprocessor when compiling. | |