logo
  • Home
  • Rank
  • Tests
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

C++ Multiple Choice Questions | MCQs | Quiz

C++ Interview Questions and Answers
Practice C++ questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Types
•   Booleans
•   Character Types
•   Integer Types
•   Floating Point Types
•   Sizes
•   Void
•   Enumerations
•   Declaration
•   Pointers
•   Arrays
•   Pointers into Arrays
•   Constants
•   References
•   Pointer to Void
•   Structures
•   Operators
•   Statements
•   Comments & Indentation
•   Function Declarations
•   Argument Passing
•   Value Return
•   Overloaded Function
•   Default Arguments
•   Unspecified Arguments
•   Pointer to Function
•   Macros
•   Modularization
•   Namespaces
•   Exceptions
•   Linkage
•   Header Files Usage
•   Classes
•   User Defined Types
•   Objects
•   Operator Functions
•   Complex Number Type
•   Conversion Operators
•   Friends
•   Large Objects
•   Essential Operators
•   Subscripting
•   Function Call
•   Dereferencing
•   Increment & Decrement
•   String Class
•   Derived Classes
•   Abstract Classes
•   Class Hierarchies
•   Abstract Classes
•   Simple String Template
•   Function Templates
•   Policy Usage Template
•   Specialization
•   Derivation & Templates
•   Error Handling
•   Grouping of Exceptions
•   Catching Exceptions
•   Resource Management
•   Exceptions Not Errors
•   Exception Specifications
•   Uncaught Exceptions
•   Exceptions & Efficiency
•   Error Handling Alternatives
•   Standard Exceptions
•   Class Hierarchies
•   Multiple Inheritance
•   Access Control
•   Run Time Type
•   Pointers to Members
•   Free Store
•   Standard Library Design
•   Container Design
•   Vector
•   Sequences
•   Sequence Adapters
•   Associative Containers
•   Almost Containers
•   Defining a New Container
•   Library Algorithms
•   Sequences / Containers
•   Function Objects
•   Nonmodifying Algorithms
•   Modifying Algorithms
•   Stored Sequences
•   Heaps
•   Min and Max
•   Permutations
•   C Style Algorithms
•   Iterators & Sequences
•   Checked Iterators
•   Allocators
•   String Characters
•   Basic String
•   C Standard Library
•   Output Stream
•   Input Stream
•   Formatting
•   File & String Streams
•   Buffering
•   Locale
•   C Input Output
•   Numeric Limits
•   Mathematical Functions
•   Vector Arithmetic
•   Numeric Algorithms
•   Random Numbers

C++ Tests

C++ Tests

Best Reference Books

C++ Books
« Prev Page
Next Page »

C++ Programming Questions and Answers – Header Files Usage

Posted on November 13, 2012 by Manish
This section on 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, 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) none of the mentioned
View Answer

Answer: b
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.
advertisement

2. Which of the following keyword is used to declare the header file?
a) include
b) exclude
c) string
d) namespace
View Answer

Answer: a
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) none of the mentioned
View Answer

Answer: a
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) none of the mentioned
View Answer

Answer: c
Explanation: In the header file, we define something that to be manipulated in the program.

5. What is the output of this program?

  1.     #include <iostream>
  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
View Answer

Answer: c
Explanation: 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.
advertisement

6. setprecision requires which of the following header file?
a) stdlib.h
b) iomanip.h
c) console.h
d) conio.h
View Answer

Answer: b
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

Answer: c
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

Answer: b
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

Answer: b
Explanation: In this fstream.h header file is used for accessing the files only.

10. What is the output of this program?

advertisement
  1.     #include <iostream>
  2.     #include <stdarg.h>
  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
View Answer

Answer: a
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.

C++ Practice Resources
C++ Mock Tests & Certification Test | 1000 C++ MCQs | 1000 C++ Algorithms | Best C++ Books
« Prev Page - C++ Programming Questions and Answers – Linkage
» Next Page - C++ Programming Questions and Answers – Classes

« C++ Programming Questions and Answers – Linkage
C++ Programming Questions and Answers – Classes »
advertisement

Deep Dive @ Sanfoundry:

  1. Programming Questions and Answers
  2. C++ Questions and Answers
  3. C# Programming Examples on LINQ
  4. C# Programming Examples on Networking
  5. C Programming Examples
  6. Java Programming Examples
  7. Java Programming Examples on File Handling
  8. C# Programming Examples
  9. C Programming Examples on File Handling
  10. C++ Programming Questions and Answers – Template Arguments to Specify Policy Usage
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.