C++ is one of the most powerful and versatile programming languages, widely used for system programming, game development, and performance-critical applications. Whether you’re a beginner or an experienced developer, it’s essential to test your understanding of key concepts in C++. Here’s a collection of 50 unique Multiple Choice Questions (MCQs) to help you evaluate your C++ skills.
1. What is the correct syntax to output “Hello, World!” in C++?
A) echo("Hello, World!");
B) System.out.println("Hello, World!");
C) cout << "Hello, World!";
D) print("Hello, World!");
Answer: C) cout << "Hello, World!";
2. What is the size of a float
data type in C++?
A) 2 bytes
B) 4 bytes
C) 8 bytes
D) 10 bytes
Answer: B) 4 bytes
3. Which of the following is a valid C++ comment?
A) // This is a comment
B) # This is a comment
C) /* This is a comment */
D) Both A and C
Answer: D) Both A and C
4. What is the default value of a static variable in C++?
A) 0
B) Null
C) Undefined
D) Garbage Value
Answer: A) 0
5. Which of the following is NOT a valid C++ identifier?
A) myVariable
B) _myVariable
C) 2ndVariable
D) my_variable2
Answer: C) 2ndVariable
6. Which operator is used to access a class’s member function in C++?
A) .
B) ->
C) :
D) ::
Answer: A) .
(dot operator is used to access member functions)
7. Which of the following is true about a constructor in C++?
A) A constructor is invoked when an object is created.
B) A constructor has no return type.
C) A constructor can be overloaded.
D) All of the above
Answer: D) All of the above
8. In C++, which keyword is used to declare a pointer?
A) ptr
B) reference
C) *
D) &
Answer: C) *
9. Which function is used to dynamically allocate memory in C++?
A) malloc()
B) alloc()
C) new
D) calloc()
Answer: C) new
10. What is the output of the following C++ code?
cppCopy codeint x = 5;
int y = 2;
cout << x / y;
A) 2.5
B) 2
C) 2.0
D) Error
Answer: B) 2
11. Which of the following is used to define a constant in C++?
A) const
B) #define
C) static
D) Both A and B
Answer: D) Both A and B
12. What is the scope of a local variable in C++?
A) Throughout the entire program
B) Within the function/block it is defined
C) In the global scope
D) In the class scope
Answer: B) Within the function/block it is defined
13. Which C++ feature allows code to be reused through inheritance?
A) Encapsulation
B) Polymorphism
C) Abstraction
D) Inheritance
Answer: D) Inheritance
14. How do you initialize an array of 5 integers in C++?
A) int arr[5] = {1, 2, 3, 4, 5};
B) int arr[5];
C) int arr = {1, 2, 3, 4, 5};
D) int[5] arr = {1, 2, 3, 4, 5};
Answer: A) int arr[5] = {1, 2, 3, 4, 5};
15. Which function is used to deallocate memory in C++?
A) free()
B) delete[]
C) destroy()
D) delete
Answer: D) delete
16. Which of the following is true for the virtual
keyword in C++?
A) It is used to declare a constant variable.
B) It is used for inheritance in classes.
C) It is used to declare a destructor.
D) It is used for dynamic polymorphism.
Answer: D) It is used for dynamic polymorphism.
17. Which of the following is a correct syntax to declare a reference variable in C++?
A) int &ref = x;
B) ref &int = x;
C) int ref = &x;
D) &int ref = x;
Answer: A) int &ref = x;
18. What is the default access modifier for members of a class in C++?
A) private
B) protected
C) public
D) private
for structures and public
for classes
Answer: A) private
19. What does the new
keyword do in C++?
A) Allocates memory on the stack
B) Allocates memory on the heap
C) Frees memory
D) Declares a variable
Answer: B) Allocates memory on the heap
20. Which of the following operators cannot be overloaded in C++?
A) +
B) =
C) ::
D) []
Answer: C) ::
21. Which of the following is used to define a function in C++?
A) func
B) def
C) void
D) function
Answer: C) void
22. Which of the following methods is used to read a string in C++?
A) cin.read()
B) cin >>
C) cin.getline()
D) getline(cin, str)
Answer: D) getline(cin, str)
23. How do you declare a constant pointer in C++?
A) const int *ptr;
B) int *const ptr;
C) const *int ptr;
D) const int ptr*;
Answer: B) int *const ptr;
24. What is the purpose of the break
statement in C++?
A) Exits the current loop or switch statement
B) Pauses the loop execution
C) Terminates the program
D) Skips the current iteration of the loop
Answer: A) Exits the current loop or switch statement
25. What does delete[]
do in C++?
A) It deallocates a pointer to a single object.
B) It deallocates a pointer to an array of objects.
C) It initializes an array of objects.
D) It allocates memory for an array.
Answer: B) It deallocates a pointer to an array of objects.
26. What is the purpose of the friend
keyword in C++?
A) It defines a relationship between classes.
B) It defines a variable as private.
C) It allows a class to access private members of another class.
D) It defines a function that is only accessible to other classes.
Answer: C) It allows a class to access private members of another class.
27. Which of the following data types cannot be used with the sizeof
operator?
A) int
B) float
C) char
D) None of the above
Answer: D) None of the above
28. Which C++ keyword is used to define a derived class?
A) extends
B) inherits
C) class
D) public
Answer: C) class
29. What does the this
pointer refer to in C++?
A) It points to the current object of the class.
B) It points to the base class object.
C) It refers to the current function.
D) It refers to the previous object in memory.
Answer: A) It points to the current object of the class.
30. What is the output of the following C++ code?
cppCopy codeint x = 10;
cout << x++;
A) 10
B) 11
C) Error
D) 0
Answer: A) 10
31. Which type of inheritance allows a class to inherit from more than one class in C++?
A) Single Inheritance
B) Multiple Inheritance
C) Multi-level Inheritance
D) Hybrid Inheritance
Answer: B) Multiple Inheritance
32. What is the result of the following C++ expression?
cppCopy codeint x = 10;
int y = 5;
cout << x % y;
A) 0
B) 1
C) 5
D) 10
Answer: A) 0
33. Which of the following is used to declare a pure virtual function in C++?
A) virtual void func() = 0;
B) void func() = 0;
C) void func();
D) virtual func() = 0;
Answer: A) virtual void func() = 0;
34. Which of the following is the correct way to declare a pointer to an integer in C++?
A) int* ptr;
B) ptr int*;
C) int ptr*;
D) ptr* int;
Answer: A) int* ptr;
35. What is the output of the following code?
cppCopy codeint x = 5;
cout << ++x;
A) 5
B) 6
C) Error
D) 0
Answer: B) 6
36. Which operator is used to define the scope of a class member in C++?
A) ->
B) .
C) ::
D) []
Answer: C) ::
37. How do you access the static members of a class in C++?
A) Using an object of the class
B) Using the ::
operator
C) Using the ->
operator
D) Using a pointer
Answer: B) Using the ::
operator
38. What does the following C++ code do?
cppCopy codeint a = 5;
int b = 10;
cout << (a > b);
A) Prints 1
B) Prints 0
C) Prints “True”
D) Prints “False”
Answer: B) Prints 0
39. Which of the following is used to handle exceptions in C++?
A) try-catch
B) throw-catch
C) exception-try
D) catch-throw
Answer: A) try-catch
40. What is the base class for all classes in C++?
A) Object
B) Base
C) class
D) std::Object
Answer: A) Object
41. What is the purpose of the continue
statement in C++?
A) It terminates the current loop.
B) It skips the current iteration and proceeds with the next iteration.
C) It causes a program to exit.
D) It breaks out of a switch statement.
Answer: B) It skips the current iteration and proceeds with the next iteration.
42. What is the correct syntax for a C++ array with 3 rows and 2 columns?
A) int arr[3][2];
B) int arr[2][3];
C) int arr[2][2];
D) int[3][2] arr;
Answer: A) int arr[3][2];
43. Which of the following is the correct way to define a function in C++?
A) function int myFunction()
B) int myFunction() {}
C) def int myFunction()
D) int myFunction() : {}
Answer: B) int myFunction() {}
44. Which type of loop is guaranteed to run at least once in C++?
A) for
loop
B) while
loop
C) do-while
loop
D) None of the above
Answer: C) do-while
loop
45. Which of the following functions is used to find the length of a C++ string?
A) size()
B) length()
C) strlen()
D) Both A and B
Answer: D) Both A and B
46. How do you declare a constant in C++?
A) int const MAX = 10;
B) const int MAX = 10;
C) int MAX = 10;
D) Both A and B
Answer: D) Both A and B
47. What is the return type of the main()
function in C++?
A) void
B) int
C) string
D) float
Answer: B) int
48. Which function is used to open a file in C++?
A) open()
B) ifstream.open()
C) ofstream.open()
D) fopen()
Answer: B) ifstream.open()
49. What is the correct syntax for calling a static method in C++?
A) object.method()
B) Class.method()
C) object::method()
D) Class::method()
Answer: D) Class::method()
50. Which of the following is a valid C++ loop structure?
A) loop
B) for
C) while
D) repeat
Answer: B) for
and C) while
These 50 unique C++ multiple-choice questions span from basic to advanced topics, helping you gauge your programming expertise in C++. Whether you’re preparing for a coding interview, a competitive exam, or just improving your skills, these questions will test your knowledge and push you to become a better C++ programmer.
Also Read: 40 Essential Multiple-Choice Questions (MCQs) on Indian Polity: A Complete Guide for Aspirants
You may also like to Read This: Unit 5: Motion of System of Particles and Rigid Body, Class 11 MCQs

Asif Iqbal Wani is a professional content writer with over 5 years of experience in the education niche. With a speciality for content creation that’s thought-provoking and engaging, Arun specializes in making study guides and resources for exams and curriculum-based content.
With a zeal for learning, Asif comes across as a vibrant educator who simplifies the most difficult concepts into information that is easily digested, enabling learners to achieve success academically. His commitment to accuracy and creativity ensures that every piece of content not only teaches but also inspires.
Asif is committed to providing high-quality impactful content that works well for different student and faculty requirements.