10 Lecture
CS201
Midterm & Final Term Short Notes
Header Files
Header files are files in C/C++ programming language that contain function and variable declarations, constants, and definitions needed to interface with other source code files. They provide a way to organize code and make it more modular, allo
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is the purpose of a header file in C/C++ programming? a) To contain function and variable declarations b) To contain executable code c) To store data d) To control the flow of the program Answer: a
Which preprocessor directive is used to include a header file in a C/C++ program? a) #define b) #include c) #ifdef d) #ifndef Answer: b
Can a header file be included multiple times in the same program? a) Yes b) No Answer: a
Which of the following is a standard C library header file? a) <iostream.h> b) <stdio.h> c) <vector.h> d) <mathematics.h> Answer: b
What is the file extension of a header file in C/C++ programming? a) .c b) .h c) .cpp d) .hpp Answer: b
Which of the following statements is true about header files? a) They contain both function and variable definitions b) They are not necessary for compiling a program c) They are used to separate interface and implementation d) They can be compiled separately from the rest of the program Answer: c
What is the purpose of a guard clause in a header file? a) To prevent multiple inclusion of the same file b) To control the flow of the program c) To define constants and macros d) To declare functions and variables Answer: a
Which of the following is not a standard C++ library header file? a) <iostream> b) <fstream> c) <vector.h> d) <string> Answer: c
Can a header file be empty? a) Yes b) No Answer: a
Which of the following statements is true about including header files? a) Including unnecessary header files can slow down compilation time b) Including header files is only necessary for large programs c) Including header files is not necessary for object-oriented programming d) Including header files does not affect the readability or maintainability of the code Answer: a
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is a header file? Answer: A header file is a file in C/C++ programming language that contains function and variable declarations, constants, and definitions needed to interface with other source code files.
How is a header file included in a C/C++ program? Answer: A header file is included in a C/C++ program using the #include preprocessor directive.
Why is it important to use header files in programming? Answer: Header files are important in programming because they provide a way to organize code and make it more modular, allowing for reuse and easier maintenance.
Can a header file contain executable code? Answer: No, a header file cannot contain executable code. It only contains function and variable declarations, constants, and definitions.
What is the purpose of a guard clause in a header file? Answer: The purpose of a guard clause in a header file is to prevent multiple inclusion of the same file.
How does a guard clause work in a header file? Answer: A guard clause in a header file uses #ifndef and #define directives to check if a macro has already been defined. If it has not been defined, the code within the guard clause is executed, and the macro is defined. If it has already been defined, the code within the guard clause is skipped.
What is the file extension of a header file in C/C++ programming? Answer: The file extension of a header file in C/C++ programming is .h.
Can a header file be compiled separately from the rest of the program? Answer: Yes, a header file can be compiled separately from the rest of the program. However, it will not produce an executable program on its own.
Can a header file be empty? Answer: Yes, a header file can be empty. However, it is not common or recommended.
What is the difference between a standard library header file and a user-defined header file? Answer: A standard library header file is provided by the C/C++ standard library and contains declarations for functions and variables that are part of the standard library. A user-defined header file is created by the programmer and contains declarations for functions and variables specific to their program.