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++?
a) cpp
b) h
c) hf
d) hg
View Answer
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?
a) include
b) exclude
c) string
d) namespace
View Answer
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
View Answer
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?
a) prototype
b) implementation
c) declarations
d) pointing
View Answer
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?
#include <iostream>
using namespace std;
int main()
{
char name[30];
cout << "Enter name: ";
gets(name);
cout << "Name: ";
puts(name);
return 0;
}
a) jobsjobs
b) jobs
c) compile time error
d) program will not run
View Answer
Explanation: This program will run on older version of C++ with the inclusion of #include
6. setprecision requires which of the following header file?
a) stdlib.h
b) iomanip.h
c) console.h
d) conio.h
View Answer
Explanation: The iomanip header file is used to correct the precision of the values.
7. Which of the following header file does not exist?
a) <iostream>
b) <string>
c) <sstring>
d) <sstream>
View Answer
Explanation: There is no such header file <sstring> in C++.
8. Which of the header file must be included to use stringstream?
a) <iostream>
b) <string>
c) <sstring>
d) <sstream>
View Answer
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?
a) ofstream.h
b) fstream.h
c) ifstream.h
d) console.h
View Answer
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?
#include <iostream>
#include <stdarg.h>
using namespace std;
float avg( int Count, ... )
{
va_list Numbers;
va_start(Numbers, Count);
int Sum = 0;
for (int i = 0; i < Count; ++i)
Sum += va_arg(Numbers, int);
va_end(Numbers);
return (Sum/Count);
}
int main()
{
float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
cout << Average;
return 0;
}
a) 4
b) 5
c) 6
d) compile time error
View Answer
Explanation: In this program, we are finding the average of first 10 numbers using stdarg header file
Output:
$ 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.
- Check C++ Books
- Apply for C++ Internship
- Check Computer Science Books
- Check Programming Books
- Apply for Computer Science Internship