Header Files Usage(C++ Programming ) Questions and Answers

Question 1.


What is the output of this program?


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
  1.    4
  2.    5
  3.    6
  4.    compile time error
Explanation:-
Answer: Option A. -> 4

In this program, we are finding the average of first 10 numbers using stdarg header file
Output:
$ g++ std.cpp
$ a.out
4




Question 2.

Which of the following header files is required for creating and reading data files?


  1.    ofstream.h
  2.    fstream.h
  3.    ifstream.h
  4.    console.h
Explanation:-
Answer: Option B. -> fstream.h

In this fstream.h header file is used for accessing the files only.




Question 3.

setprecision requires which of the following header file?


  1.    stdlib.h
  2.    iomanip.h
  3.    console.h
  4.    conio.h
Explanation:-
Answer: Option B. -> iomanip.h

The iomanip header file is used to correct the precision of the values.



Question 4.


What is the output of this program?


1.
#include
2.
using namespace std;
3.
int main()
4.
{
5.
char name[30];
6.
cout
  1.    jobsjobs
  2.    jobs
  3.    compile time error
  4.    program will not run
Explanation:-
Answer: Option C. -> compile time error

In this program,we need to string header file to run this program.



Question 5.

What does a default header file contain?


  1.    prototype
  2.    implementation
  3.    declarations
  4.    none of the mentioned
Explanation:-
Answer: Option C. -> declarations

In the header file, we define something that to be manipulated in the program.



Question 6.

Identify the incorrect statement.


  1.    iostream is a standard header and iostream.h is a non-standard header.
  2.    iostream is a non-standard header and iostream.h is a non-standard header.
  3.    iostream is a standard header and iostream.h is a standard header.
  4.    none of the mentioned
Explanation:-
Answer: Option A. -> iostream is a standard header and iostream.h is a non-standard header.

The iostream.h is used in the older versions of c++ and iostream is evolved from it in the std 

namespace.



Question 7.

What is the user-defined header file extension in c++?


  1.    cpp
  2.    h
  3.    hf
  4.    none of the mentioned
Explanation:-
Answer: Option B. -> h

None.



Question 8.

Which of the following keyword is used to declare the header file?


  1.    include
  2.    exclude
  3.    string
  4.    namespace
Explanation:-
Answer: Option A. -> include

The include keyword is used to include all the required things to execute the given code 

in the program.