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
  1. 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

  1. Which pre-processor directive is used to include header files in a C program? a) #include b) #define c) #ifdef d) #ifndef

Answer: a

  1. 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

  1. Which pre-processor directive is used to define a macro in C programming? a) #define b) #include c) #ifdef d) #ifndef

Answer: a

  1. 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

  1. 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

  1. 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

  1. Which pre-processor directive is used to undefine a macro in C programming? a) #undef b) #define c) #ifdef d) #ifndef

Answer: a

  1. 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

  1. 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
  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. How is a macro undefined in C programming? Answer: A macro is undefined using the #undef directive followed by the macro name.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

In C programming, the pre-processor is a program that performs preprocessing tasks on the code before it is compiled. These tasks include handling pre-processor directives and including header files. The pre-processor is executed before the compiler and is a separate component of the C programming environment. One of the primary functions of the pre-processor is to handle pre-processor directives. Pre-processor directives are instructions that begin with the # symbol and are used to control the pre-processor's behavior. Some of the most commonly used pre-processor directives include #define, #include, #ifdef, and #ifndef. The #define directive is used to define a macro, which is a text replacement that is expanded by the pre-processor. Macros are commonly used to simplify repetitive or complex code or to provide a way to include conditional compilation in the code. The #include directive is used to include header files that contain declarations for functions, constants, and other objects used in the code. Header files are used to organize code and make it easier to reuse in other programs. The #ifdef and #ifndef directives are used to control conditional compilation. The #ifdef directive includes a block of code if a certain macro has been defined, while the #ifndef directive includes a block of code if a certain macro has not been defined. In addition to these directives, the pre-processor also supports other features such as the #pragma directive, which is used to specify implementation-specific behavior or provide hints to the compiler. While pre-processor directives can be powerful tools for controlling the behavior of the pre-processor and the code that is generated, excessive use of these directives can make the code hard to read, maintain, and debug. As such, it is important to use pre-processor directives judiciously and only when necessary.