Here is a listing of C++ interview questions on “Header Files Usage” along with answers, explanations and/or solutions:
1. What is the user-defined header file extension in c++?
Explanation: .h extensions are used for user defined header files. To include a user defined header file one should use #include”name.h” i.e. enclosed within double quotes.
2. Which of the following keyword is used to declare the header file?
Explanation: The include keyword is used to include all the required things to execute the given code in the program.
3. Identify the incorrect statement.
a) iostream is a standard header and iostream.h is a non-standard header
b) iostream is a non-standard header and iostream.h is a non-standard header
c) iostream is a standard header and iostream.h is a standard header
d) iostream is a non-standard header
Explanation: The iostream.h is used in the older versions of c++ and iostream is evolved from it in the std namespace.
4. What does a default header file contain?
Explanation: In the header file, we define something that to be manipulated in the program.
5. What will be the output of the following C++ code?
using namespace std;
cout << "Enter name: ";
cout << "Name: ";
c) compile time error
d) program will not run
Explanation: This program will run on older version of C++ with the inclusion of #include
6. setprecision requires which of the following header file?
Explanation: The iomanip header file is used to correct the precision of the values.
7. Which of the following header file does not exist?
Explanation: There is no such header file <sstring> in C++.
8. Which of the header file must be included to use stringstream?
Explanation: stringstream is available under the header file <string> in C++.
9. Which of the following header files is required for creating and reading data files?
Explanation: In this fstream.h header file is used for accessing the files only.
10. What will be the output of the following C++ code?
using namespace std;
float avg( int Count, ... )
int Sum = 0;
for (int i = 0; i < Count; ++i)
Sum += va_arg(Numbers, int);
float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
cout << Average;
d) compile time error
Explanation: In this program, we are finding the average of first 10 numbers using stdarg header file
$ g++ std.cpp $ a.out 4
Sanfoundry Global Education & Learning Series – C++ Programming Language.
To practice all areas of C++ language, here is complete set of 1000+ Multiple Choice Questions and Answers.