C++ interview questions and answers focuses on “Header Files Usage”. One shall practice these interview questions to improve their C++ programming skills needed for various interviews ,campus interviews, walk-in 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.
C++ interview questions on “Header Files Usage” along with answers, explanations and/or solutions:
Q 1. What is the user-defined header file extension in c++?
A. cpp
B. h
C. hf
D. hg
Show Answer
Answer:-B. hExplanation
.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.Q 2. Which of the following keyword is used to declare the header file?
A. exclude
B. include
C. string
D. namespace
Show Answer
Answer:-B. includeExplanation
The include keyword is used to include all the required things to execute the given code in the program.Q 3. Identify the incorrect statement.
A. iostream 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 standard header and iostream.h is a non-standard header
Show Answer
Answer:-D. iostream is a standard header and iostream.h is a non-standard headerExplanation
The iostream.h is used in the older versions of c++ and iostream is evolved from it in the std namespace.Q 4. What does a default header file contain?
A. prototype
B. implementation
C. pointing
D. declarations
Show Answer
Answer:-D. declarationsExplanation
In the header file, we define something that to be manipulated in the program.Q 5. setprecision requires which of the following header file?
A. iomanip.h
B. stdlib.h
C. console.h
D. conio.h
Show Answer
Answer:-A. iomanip.hExplanation
The iomanip header file is used to correct the precision of the values.Q 6. Which of the following header file does not exist?
A. <iostream>
B. <string>
C. <sstring>
D. <sstream>
Show Answer
Answer:-C.Explanation
There is no such header fileQ 7. Which of the header file must be included to use stringstream?
A. <iostream>
B. <sstream>
C. <sstring>
D. <string>
Show Answer
Answer:-D.Explanation
stringstream is available under the header fileQ 8. Which of the following header files is required for creating and reading data files?
A. ofstream.h
B. ifstream.h
C. fstream.h
D. console.h
Show Answer
Answer:-C. fstream.hExplanation
In this fstream.h header file is used for accessing the files only.Q 9. 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
Show Answer
Answer:-A. 4Explanation
In this program, we are finding the average of first 10 numbers using stdarg header file Output: $ g++ std.cpp $ a.out 4Q 10. 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
Leave a Reply