Here are 1000 MCQs on C++ (Chapterwise).
1. Who invented C++?
a) Dennis Ritchie
b) Ken Thompson
c) Brian Kernighan
d) Bjarne Stroustrup
2. What is C++?
a) C++ is an object oriented programming language
b) C++ is a procedural programming language
c) C++ supports both procedural and object oriented programming language
d) C++ is a functional programming language
View Answer
3. Which of the following is the correct syntax of including a user defined header files in C+
+?
a) #include [userdefined]
b) #include “userdefined”
c) #include <userdefined.h>
d) #include <userdefined>
View Answer
4. Which of the following is used for comments in C++?
a) /* comment */
b) // comment */
c) // comment
d) both // comment or /* comment */
View Answer
5. Which of the following user-defined header file extension used in c++?
a) hg
b) cpp
c) h
d) hf
View Answer
advertisement
6. Which of the following is a correct identifier in C++?
a) VAR_1234
b) $var_name
c) 7VARNAME
d) 7var_name
View Answer
7. Which of the following is not a type of Constructor in C++?
a) Default constructor
b) Parameterized constructor
c) Copy constructor
d) Friend constructor
View Answer
8. Which of the following approach is used by C++?
a) Left-right
b) Right-left
c) Bottom-up
d) Top-down
View Answer
9. What is virtual inheritance in C++?
a) C++ technique to enhance multiple inheritance
b) C++ technique to ensure that a private member of the base class can be accessed
somehow
c) C++ technique to avoid multiple inheritances of classes
d) C++ technique to avoid multiple copies of the base class into children/derived class
View Answer
10. What happens if the following C++ statement is compiled and executed?
int *ptr = NULL;
delete ptr;
a) The program is not semantically correct
b) The program is compiled and executed successfully
c) The program gives a compile-time error
d) The program compiled successfully but throws an error during run-time
View Answer
11. What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
char s1[6] = "Hello";
char s2[6] = "World";
char s3[12] = s1 + " " + s2;
cout<<s3;
return 0;
}
a) Hello
b) World
c) Error
d) Hello World
View Answer
advertisement
12. What is the difference between delete and delete[] in C++?
a) delete is syntactically correct but delete[] is wrong and hence will give an error if used in
any case
b) delete is used to delete normal objects whereas delete[] is used to pointer objects
c) delete is a keyword whereas delete[] is an identifier
d) delete is used to delete single object whereas delete[] is used to multiple(array/pointer of)
objects
View Answer
13. What happens if the following program is executed in C and C++?
#include <stdio.h>
int main(void)
{
int new = 5;
printf("%d", new);
}
a) Error in C and successful execution in C++
b) Error in both C and C++
c) Error in C++ and successful execution in C
d) A successful run in both C and C++
View Answer
advertisement
14. What happens if the following program is executed in C and C++?
#include <stdio.h>
void func(void)
{
printf("Hello");
}
void main()
{
func();
func(2);
}
a) Outputs Hello twice in both C and C++
b) Error in C and successful execution in C++
c) Error in C++ and successful execution in C
d) Error in both C and C++
View Answer
15. Which of the following is correct about this pointer in C++?
a) this pointer is passed as a hidden argument in all static variables of a class
b) this pointer is passed as a hidden argument in all the functions of a class
c) this pointer is passed as a hidden argument in all non-static functions of a class
d) this pointer is passed as a hidden argument in all static functions of a class
View Answer
16. What will be the output of the following C++ code?
1. #include <iostream>
2. #include <string>
3. #include <algorithm>
4. using namespace std;
5. int main()
6. {
7. string s = "spaces in text";
8. s.erase(remove(s.begin(), s.end(), ' ' ), s.end() ) ;
9. cout << s << endl;
10. }
a) spacesintext
b) spaces in text
c) spaces
d) spaces in
View Answer
17. Which of the following C++ code will give error on compilation?
================code 1=================
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
cout<<"Hello World";
return 0;
}
========================================
================code 2=================
#include <iostream>
int main(int argc, char const *argv[])
{
std::cout<<"Hello World";
return 0;
}
========================================
a) Code 1 only
b) Neither code 1 nor code 2
c) Both code 1 and code 2
d) Code 2 only
View Answer
18. Which of the following type is provided by C++ but not C?
a) double
b) float
c) int
d) bool
View Answer
19. What is the value of p in the following C++ code snippet?
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int p;
6. bool a = true;
7. bool b = false;
8. int x = 10;
9. int y = 5;
10. p = ((x | y) + (a + b));
11. cout << p;
12. return 0;
13. }
a) 12
b) 0
c) 2
d) 16
View Answer
20. By default, all the files in C++ are opened in _________ mode.
a) Binary
b) VTC
c) Text
d) ISCII
View Answer
21. What will be the output of the following C++ function?
1. int main()
2. {
3. register int i = 1;
4. int *ptr = &i;
5. cout << *ptr;
6. return 0;
7. }
a) Runtime error may be possible
b) Compiler error may be possible
c) 1
d) 0
View Answer
22. Which of the following correctly declares an array in C++?
a) array{10};
b) array array[10];
c) int array;
d) int array[10];
View Answer
23. What is the size of wchar_t in C++?
a) Based on the number of bits in the system
b) 2 or 4
c) 4
d) 2
View Answer
24. What will be the output of the following C++ code?
#include<iostream>
using namespace std;
int main ()
{
int cin;
cin >> cin;
cout << "cin: " << cin;
return 0;
}
a) Segmentation fault
b) Nothing is printed
c) Error
d) cin: garbage value
View Answer
25. What is the use of the indentation in c++?
a) r distinguishes between comments and inner data
b) distinguishes between comments and outer data
c) distinguishes between comments and code
d) r distinguishes between comments and outer data
View Answer
26. Which is more effective while calling the C++ functions?
a) call by object
b) call by pointer
c) call by value
d) call by reference
View Answer
27. What will be the output of the following C++ program?
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(int argc, char const *argv[])
{
const char *a = "Hello\0World";
cout<<a;
return 0;
}
a) Hello
b) World
c) Error
d) Hello World
View Answer
28. Which of the following is used to terminate the function declaration in C++?
a) ;
b) ]
c) )
d) :
View Answer
29. What will be the output of the following C++ code?
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. char c = 74;
6. cout << c;
7. return 0;
8. }
a) I
b) J
c) A
d) N
View Answer
30. What will be the output of the following C++ program?
1. #include <iomanip>
2. #include <iostream>
3. using namespace std;
4. int main()
5. {
6. cout << setprecision(17);
7. double d = 0.1;
8. cout << d << endl;
9. return 0;
10. }
a) compile time error
b) 0.100001
c) 0.11
d) 0.10000000000000001
View Answer
31. Which keyword is used to define the macros in c++?
a) #macro
b) #define
c) macro
d) define
View Answer
32. What is the correct syntax of accessing a static member of a class in C++?
---------------------------
Example class:
class A
{
public:
static int value;
}
---------------------------
a) A->value
b) A^value
c) A.value
d) A::value
View Answer
33. The C++ code which causes abnormal termination/behaviour of a program should be
written under _________ block.
a) catch
b) throw
c) try
d) finally
View Answer
34. What is Inheritance in C++?
a) Deriving new classes from existing classes
b) Overloading of classes
c) Classes with same names
d) Wrapping of data into a single class
View Answer
35. What will be the output of the following C++ code?
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int a = 5;
6. float b;
7. cout << sizeof(++a + b);
8. cout << a;
9. return 0;
10. }
a) 2 5
b) 4 5
c) 4 6
d) 2 6
View Answer
36. Which of the following symbol is used to declare the preprocessor directives in C++?
a) $
b) ^
c) #
d) *
View Answer
37. What will be the output of the following C++ program?
#include<iostream>
using namespace std;
int main()
{
int a = 5;
auto check = [=]()
{
a = 10;
};
check();
cout<<"Value of a: "<<a<<endl;
return 0;
}
a) Segmentation fault
b) Value of a: 5
c) Value of a: 10
d) Error
View Answer
38. What will be the output of the following C++ code?
#include <iostream>
using namespace std;
void square (int *x, int *y)
{
*x = (*x) * --(*y);
}
int main ( )
{
int number = 30;
square(&number, &number);
cout << number;
return 0;
}
a) 30
b) Error
c) Segmentation fault
d) 870
View Answer
39. What is meant by a polymorphism in C++?
a) class having only single form
b) class having four forms
c) class having many forms
d) class having two forms
View Answer
40. What will be the output of the following C++ program?
#include <iostream>
#include <string>
using namespace std;
int main ()
{
std::string str ("Sanfoundry.");
str.back() = '!';
std::cout << str << endl;
return 0;
}
a) Sanfoundry!
b) Sanfoundry!.
c) Sanfoundry.
d) Sanfoundry.!
View Answer
41. Pick the incorrect statement about inline functions in C++?
a) Saves overhead of a return call from a function
b) They are generally very large and complicated function
c) These functions are inserted/substituted at the point of call
d) They reduce function call overheads
View Answer
42. What will be the output of the following C++ program?
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int n = 5;
6. void *p = &n;
7. int *pi = static_cast<int*>(p);
8. cout << *pi << endl;
9. return 0;
10. }
a) 5
b) 6
c) compile time error
d) runtime error
View Answer
43. What is abstract class in C++?
a) Any Class in C++ is an abstract class
b) Class from which any class is derived
c) Class specifically used as a base class with atleast one virtual functions
d) Class specifically used as a base class with atleast one pure virtual functions
View Answer
44. Which of the following constructors are provided by the C++ compiler if not defined in a
class?
a) Copy constructor
b) Default constructor
c) Assignment constructor
d) All of the mentioned
View Answer
45. What will be the output of the following C++ program?
#include <iostream>
using namespace std;
int main()
{
try
{
try
{
throw 20;
}
catch (int n)
{
cout << "Inner Catch\n";
throw;
}
}
catch (int x)
{
cout << "Outer Catch\n";
}
return 0;
}
a) Outer Catch
b)
Inner Catch
Outer Catch
c) Error
d) Inner Catch
View Answer
46. Which concept allows you to reuse the written code in C++?
a) Inheritance
b) Polymorphism
c) Abstraction
d) Encapsulation
View Answer
47. What will be the output of the following C++ code snippet?
1. #include <iostream>
2. using namespace std;
3. int operate (int a, int b)
4. {
5. return (a * b);
6. }
7. float operate (float a, float b)
8. {
9. return (a / b);
10. }
11. int main()
12. {
13. int x = 5, y = 2;
14. float n = 5.0, m = 2.0;
15. cout << operate(x, y) <<"\t";
16. cout << operate (n, m);
17. return 0;
18. }
a) 10.0 5
b) 10 2.5
c) 10.0 5.0
d) 5.0 2.5
View Answer
48. How structures and classes in C++ differ?
a) Structures by default hide every member whereas classes do not
b) In Structures, members are public by default whereas, in Classes, they are private by
default
c) Structures cannot have private members whereas classes can have
d) In Structures, members are private by default whereas, in Classes, they are public by
default
View Answer
49. What will be the output of the following C++ code?
1. #include <iostream>
2. using namespace std;
3. int main ()
4. {
5. int a, b, c;
6. a = 2;
7. b = 7;
8. c = (a > b) ? a : b;
9. cout << c;
10. return 0;
11. }
a) 12
b) 14
c) 6
d) 7
View Answer
50. What is the benefit of c++ input and output over c input and output?
a) Both Type safety & Exception
b) Sequence container
c) Exception
d) Type safety
View Answer
51. What will be the output of the following C++ code snippet?
1. #include <stdio.h>
2. #include<iostream>
3. using namespace std;
4. int main ()
5. {
6. int array[] = {0, 2, 4, 6, 7, 5, 3};
7. int n, result = 0;
8. for (n = 0; n < 8; n++)
9. {
10. result += array[n];
11. }
12. cout << result;
13. return 0;
14. }
a) 21
b) 27
c) 26
d) 25
View Answer
52. What will be the output of the following C++ program?
1. #include <iostream>
2. #include <string>
3. using namespace std;
4. int main ()
5. {
6. string str ("Sanfoundry");
7. for (size_t i = 0; i < str.length();)
8. {
9. cout << str.at(i-1);
10. }
11. return 0;
12. }
a) runtime error
b) Sanfo
c) S
d) Sanfoundry
View Answer
53. What will be the output of the following C++ program?
#include <iostream>
using namespace std;
class A{
public:
A(){
cout<<"Constructor called\n";
}
~A(){
cout<<"Destructor called\n";
}
};
int main(int argc, char const *argv[])
{
A *a = new A[5];
delete[] a;
return 0;
}
a) Segmentation fault
b) “Constructor called” five times and then “Destructor called” five times
c) “Constructor called” five times and then “Destructor called” once
d) Error
View Answer
Chapterwise Multiple Choice Questions on C++
Our 1000+ MCQs focus on all topics of the C++ Programming subject, covering 100+
topics. This will help you to prepare for exams, contests, online tests, quizzes, viva-voce,
interviews, and certifications. You can practice these MCQs chapter by chapter starting
from the 1st chapter or you can jump to any chapter of your choice. You can also download
the PDF of C++ Programming MCQs by applying below.
1. C++ Basic Concepts
2. C++ Types, Pointers, Arrays & Structures
3. C++ Functions, Namespaces & Exceptions
4. C++ Source Files, Classes and Operator Overloading
5. C++ Derived Classes, C++ Templates & Exception Handling
6. C++ Class Hierarchies, C++ Library & Containers
7. C++ Algorithms, Objects & Iterators
8. C++ Strings, Streams & Numerics
9. Advanced C++
1. C++ MCQ on Basic Concepts
The section contains C++ multiple choice questions and answers on basics, oops concepts,
c++ concepts, static constant keyword, differences between c and c++.
C++ Basics C++ vs C
C++ OOPs Concept – 1 C++ Concepts – 1
C++ OOPs Concept – 2 C++ Concepts – 2
C++ OOPs Concept – 3 C++ Concepts – 3
C++ OOPs Concept – 4 Static Constant Keyword
2. C++ MCQ on Types, Pointers, Arrays & Structures
The section contains C++ questions and answers on integer, float, character and boolean
types. It also contains arrays, pointers, references and structures.
C++ Types C++ Arrays
C++ Booleans C++ Pointers into Arrays
C++ Character Types C++ Constants
C++ Integer Types C++ References – 1
C++ Floating Point Types C++ References – 2
C++ Sizes C++ References – 3
C++ Void
C++ Pointer to Void
C++ Enumerations
C++ Structures
C++ Declaration
C++ Character Classification
C++ Pointers
3. C++ Programming Multiple Choice Questions on Functions,
Namespaces & Exceptions
The section contains C++ MCQs on function declaration and overloading, operators and
statements, values and arguments, macros, namespaces and exceptions.
C++ Operators C++ Default Arguments
C++ Statements Unspecified Number of
C++ Comments and Arguments
Indentation Pointer to Function
C++ Function Declarations C++ Macros
C++ Functions C++ Modularization and
C++ Argument Passing Interfaces
C++ Value Return C++ Namespaces – 1
C++ Overloaded Function C++ Namespaces – 2
Names C++ Exceptions
4. C++ MCQ on Source Files, Classes and Operator Overloading
The section contains C++ multiple choice questions and answers on classes and functions,
fiend function, objects and operators, operator overloading, constructors and destructors,
subscripting and dereferencing and other string classes.
C++ Large Objects
C++ Linkage
C++ Essential Operators
C++ Header Files Usage
C++ Subscripting
C++ Classes – 1
C++ Function Call
C++ Classes – 2
C++ Dereferencing
C++ User Defined Types
C++ Increment and
C++ Objects
Decrement
C++ Operator Functions
C++ String Class
C++ Operator Overloading –
C++ String – 1
1
C++ String – 2
C++ Operator Overloading –
C++ Constructors and
2
Destructors – 1
C++ Complex Number Type
C++ Constructors and
C++ Conversion Operators
Destructors – 2
C++ Friends
C++ Constructors and
C++ Friend Function
Destructors – 3
5. C++ Programming MCQ on Derived Classes, Templates & Exception
Handling
The section contains C++ Programming questions and answers on different types of
classes like abstract, derived and their hierarchies, different types of templates like simple
string and function and their derivation and specialization. The section also has error and
exception handling, different types of exceptions and their resource management.
C++ Derived Classes
C++ Abstract Classes – 1 C++ Error Handling
C++ Abstract Classes – 2 Grouping of Exceptions
Design of Class Hierarchies C++ Catching Exceptions
C++ Class Hierarchies & C++ Resource Management
Abstract Classes Exceptions That Are Not
C++ String Template Errors
C++ Function Templates – 1 Exception Specifications
C++ Function Templates – 2 Uncaught Exceptions
C++ Class Templates C++ Exceptions and
C++ Template Arguments for Efficiency
Policy Usage C++ Exception Handling – 1
C++ Specialization C++ Exception Handling – 2
C++ Derivation and C++ Exception Handling – 3
Templates C++ Error Handling
C++ Standard Template Alternatives
Library C++ Standard Exceptions
C++ Templates
6. C++ MCQ on Class Hierarchies, Library & Containers
The section contains C++ MCQs on different aspects of a container which includes creation
and design of new containers, vectors and sequences, types of inheritance and various
class hierarchies, sequences like seq_con array class, seq_con vector class, stl – pair and
heap, vtable, vptr, generators, array type manipulations, tuples, complex library, valarray,
bitset and class relationships.
C++ Class Hierarchies seq_con Vector Class – 2
C++ Multiple Inheritance seq_con List
C++ Inheritance – 1 STL – Pair
C++ Inheritance – 2 STL Container Any – 1
C++ Access Control STL Container Any – 2
C++ Run Time Type STL- Heap
Information vtable and vptr
Pointers to Members C++ Generators
Free Store Array Type Manipulation
C++ Standard Library Design
C++ Tuples – 1
C++ Container Design
C++ Tuples – 2
C++ Vector
C++ Complex Library – 1
C++ Sequences
C++ Complex Library – 2
C++ Sequence Adapters
C++ Valarray
C++ Associative Containers
C++ Bitset – 1
Almost Containers
C++ Bitset – 2
Defining a New Container
C++ Bitset – 3
seq_con Array Class – 1
C++ Class Relationships
seq_con Array Class – 2
More Containers
seq_con Vector Class – 1
7. Multiple Choice Questions on C++ Algorithms, Objects & Iterators
The section contains C++ multiple choice questions and answers on different types of
algorithms like C style, standard library, modifying sequence and non modifying sequence,
different types of iterators, stl algorithms, functors, sequences, containers and allocators.
C++ Standard Library
Algorithms
C++ Sequences and C++ Permutations
Containers C Style Algorithms
C++ Function Objects C++ Iterators and Sequences
C++ Nonmodifying Sequence C++ Checked Iterators
Algorithms C++ Allocators
C++ Modifying Sequence Iterators
Algorithms C++ STL Algorithms
C++ Stored Sequences C++ Functors
C++ Heaps
C++ Min and Max
8. C++ Programming MCQs on Strings, Streams & Numerics
The section contains C++ Programming questions and answers on basic strings and their
characters, I/O streams, file and string streams, standard library and mathematical
applications like numeric limits, file handling, vector arithmetic and random numbers.
C++ String Characters C++ Locale
C++ Basic String C Input Output
C Standard Library C++ Numeric Limits
C++ Output Stream Standard Mathematical
C++ Input Stream Functions
C++ Formatting Vector Arithmetic
C++ File Streams and String Generalized Numeric
Streams Algorithms
C++ Random Numbers
C++ Buffering
C++ File Handling
9. Multiple Choice Questions on Advanced C++
The section contains C++ MCQs on lambda expressions and command line arguments.
C++ Command Line
C++ Lambda Expressions
Arguments
If you would like to learn "C++" thoroughly, you should attempt to work on the complete set
of 1000+ MCQs - multiple choice questions and answers mentioned above. It will
immensely help anyone trying to crack an exam or an interview.
Note: We are working on pdf download for C++ MCQs and will publish the download link
here. Fill this C++ mcq pdf download request form for download notification.
Wish you the best in your endeavor to learn and master C++!
Important Links:
C++ Books
C++ Programming Books
Object Oriented Programming in C++ Books
C++ Online Test
C++ Certification Contest
C++ Internship
C Multiple Choice Questions
Java Multiple Choice Questions
Python Multiple Choice Questions
C# Multiple Choice Questions
Data Structures Multiple Choice Questions
Programming Multiple Choice Questions
Computer Science Multiple Choice Questions