Skip to main content

Important Introduction to Programming Short Questions

Chapter: 23
Question 1:
What is a header file in C?
Answer: A header file contains function prototypes, symbolic constants, and macros, typically with a .h extension.
Chapter: 23
Question 2:
What is the purpose of the #define directive?
Answer: It defines macros, which are constants or functions that get substituted into the code.
Chapter: 23
Question 3:
How does the #undef directive work?
Answer: It removes the definition of a macro, allowing it to be redefined.
Chapter: 23
Question 4:
What is conditional compilation in C?
Answer: It allows parts of code to be compiled only if certain conditions are met, using directives like #ifdef.
Chapter: 23
Question 5:
What is the purpose of the #ifdef directive?
Answer: It checks if a macro is defined before compiling the code enclosed by it.
Chapter: 23
Question 6:
Why should macros with arguments be enclosed in parentheses?
Answer: To ensure correct evaluation order and avoid precedence issues.
Chapter: 23
Question 7:
How does using a macro differ from using a function?
Answer: Macros are expanded at compile-time, avoiding function call overhead, whereas functions incur runtime overhead.
Chapter: 23
Question 8:
What does #error directive do in C?
Answer: It generates a compile-time error message if a certain condition is met.
Chapter: 23
Question 9:
Why might you use #pragma in C?
Answer: #pragma is used for implementation-specific features or optimizations.
Chapter: 23
Question 10:
How does the #line directive affect compilation?
Answer: It sets the line number and filename for error messages and debugging output.