250+ TOP MCQs on Header Files Usage and Answers

This section on C++ interview questions and answers on “Header Files Usage”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. These questions can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ interview questions come with detailed explanation of the answers which helps in better understanding of C++ concepts.

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
Answer: b
Clarification: .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
Answer: a
Clarification: 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
Answer: a
Clarification: The iostream.h is used in the older versions of c++ and iostream is evolved from it in the std namespace.

  250+ TOP MCQs on Pointers to Members and Answers

4. What does a default header file contain?
a) prototype
b) implementation
c) declarations
d) pointing
Answer: c
Clarification: 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?

  1.     #include 
  2.     using namespace std;
  3.     int main()
  4.     {
  5.         char name[30];
  6.         cout << "Enter name: ";
  7.         gets(name);
  8.         cout << "Name: ";
  9.         puts(name);
  10.         return 0;
  11.     }

a) jobsjobs
b) jobs
c) compile time error
d) program will not run
Answer: c
Clarification: This program will run on older version of C++ with the inclusion of #include header file, but for on new compiler C++14 and above the gets is removed from the header file so it will not run on them even after inclusion of cstdio header file.

6. setprecision requires which of the following header file?
a) stdlib.h
b) iomanip.h
c) console.h
d) conio.h
Answer: b
Clarification: The iomanip header file is used to correct the precision of the values.

7. Which of the following header file does not exist?
a)
b)
c)
d)
Answer: c
Clarification: There is no such header file in C++.

8. Which of the header file must be included to use stringstream?
a)
b)
c)
d)
Answer: b
Clarification: stringstream is available under the header file 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
Answer: b
Clarification: In this fstream.h header file is used for accessing the files only.

10. What will be the output of the following C++ code?

  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     float avg( int Count, ... )
  5.     {
  6.         va_list Numbers;
  7.         va_start(Numbers, Count);
  8.         int Sum = 0;
  9.         for (int i = 0; i < Count; ++i)
  10.             Sum += va_arg(Numbers, int);
  11.         va_end(Numbers);
  12.         return (Sum/Count);
  13.     }
  14.     int main()
  15.     {
  16.         float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
  17.         cout << Average;
  18.         return 0;
  19.     }

a) 4
b) 5
c) 6
d) compile time error
Answer: a
Clarification: In this program, we are finding the average of first 10 numbers using stdarg header file
Output:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top