23 Lecture
CS201
Midterm & Final Term Short Notes
Pre-processor
In computer programming, a pre-processor is a program or a part of a compiler that performs pre-processing, which is the initial phase of translation from human-readable source code to machine-executable code. The pre-processor is responsible fo
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- What is the pre-processor in C programming? a) A program that executes before the compiler b) A part of the compiler that optimizes code c) A program that executes after the compiler d) A part of the compiler that performs type checking
Answer: a
- Which pre-processor directive is used to include header files in a C program? a) #include b) #define c) #ifdef d) #ifndef
Answer: a
- What does the #define directive do in C programming? a) Defines a constant value or a macro b) Includes a header file c) Conditionally compiles code d) Expands a pre-defined macro
Answer: a
- Which pre-processor directive is used to define a macro in C programming? a) #define b) #include c) #ifdef d) #ifndef
Answer: a
- What is the purpose of the #ifdef directive in C programming? a) To include a header file if a macro is defined b) To exclude a block of code if a macro is not defined c) To define a macro d) To conditionally compile code
Answer: b
- Which pre-processor directive is used to conditionally compile code based on a certain condition? a) #define b) #include c) #ifdef d) #if
Answer: d
- What is the purpose of the #ifndef directive in C programming? a) To define a macro b) To include a header file if a macro is not defined c) To exclude a block of code if a macro is defined d) To conditionally compile code
Answer: b
- Which pre-processor directive is used to undefine a macro in C programming? a) #undef b) #define c) #ifdef d) #ifndef
Answer: a
- What does the #pragma directive do in C programming? a) Specifies implementation-specific behavior b) Defines a macro c) Includes a header file d) Expands a pre-defined macro
Answer: a
- Which pre-processor directive is used to generate code automatically based on templates or other input files? a) #define b) #include c) #ifdef d) #pragma
Answer: b
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is the purpose of the pre-processor in C programming? Answer: The pre-processor performs pre-processing tasks such as handling pre-processor directives and including header files before the code is compiled.
What is a macro in C programming? Answer: A macro is a pre-processor directive that defines a text replacement that is expanded by the pre-processor.
How is a macro defined in C programming? Answer: A macro is defined using the #define directive followed by the macro name and its replacement text.
What is the purpose of the #include directive in C programming? Answer: The #include directive is used to include header files that contain function prototypes, constant definitions, and other declarations needed in the source code.
What is the purpose of the #ifdef directive in C programming? Answer: The #ifdef directive is used to include or exclude blocks of code depending on whether a certain macro has been defined.
How is a macro undefined in C programming? Answer: A macro is undefined using the #undef directive followed by the macro name.
What is conditional compilation in C programming? Answer: Conditional compilation is the process of including or excluding blocks of code based on certain conditions such as the target platform or the compiler being used.
What is the purpose of the #pragma directive in C programming? Answer: The #pragma directive is used to specify implementation-specific behavior or provide hints to the compiler.
What are the potential risks of using pre-processor directives excessively in C programming? Answer: Overuse of pre-processor directives can lead to code that is hard to read, maintain, and debug. It can also make the code more error-prone.
Can pre-processor directives be used in languages other than C? Answer: Yes, many programming languages have pre-processor directives, including C++, Objective-C, and Fortran.