Top 50 C++ Interview Questions
Carefully selected for product companies, MNCs, and technical interviews.
1. What is C++?⌄
C++ is a high-performance programming language that supports procedural, object-oriented, and generic programming.
2. Difference between C and C++?⌄
C is procedural, while C++ supports object-oriented programming with classes and objects.
3. What are OOP principles?⌄
Encapsulation, Abstraction, Inheritance, and Polymorphism.
4. What is a class?⌄
A class is a blueprint for creating objects.
5. What is an object?⌄
An object is an instance of a class.
6. What is constructor?⌄
A constructor initializes an object when it is created.
7. What is destructor?⌄
A destructor releases resources when an object is destroyed.
8. What is inheritance?⌄
Inheritance allows a class to acquire properties of another class.
9. What is polymorphism?⌄
Polymorphism allows the same function to behave differently.
10. What is function overloading?⌄
Multiple functions with the same name but different parameters.
11. What is operator overloading?⌄
Giving special meaning to operators for user-defined types.
12. What is a virtual function?⌄
A function that supports runtime polymorphism.
13. What is abstract class?⌄
A class with at least one pure virtual function.
14. What is STL?⌄
Standard Template Library provides containers, algorithms, and iterators.
15. What is vector?⌄
A dynamic array that resizes automatically.
16. What is memory leak?⌄
Allocated memory that is not properly released.
17. What is dangling pointer?⌄
Pointer referencing freed memory.
18. What is smart pointer?⌄
Smart pointers manage memory automatically (unique_ptr, shared_ptr).
19. What is RAII?⌄
Resource Acquisition Is Initialization ensures safe resource handling.
20. What is namespace?⌄
Prevents naming conflicts by grouping identifiers.
21. What is template?⌄
Templates allow writing generic and reusable code.
22. What is exception handling?⌄
Handling runtime errors using try, catch, and throw.
23. What is multithreading?⌄
Executing multiple threads concurrently.
24. What is deadlock?⌄
Threads waiting indefinitely for resources.
25. What is lambda expression?⌄
An anonymous inline function introduced in C++11.
26. What is auto keyword?⌄
Automatically deduces variable type.
27. What is move semantics?⌄
Transfers resources instead of copying.
28. What is rvalue reference?⌄
Used to implement move semantics.
29. What is nullptr?⌄
Type-safe null pointer introduced in C++11.
30. What is explicit constructor?⌄
Prevents implicit type conversion.
31. What is final keyword?⌄
Prevents inheritance or overriding.
32. What is override keyword?⌄
Ensures correct method overriding.
33. What is shallow copy?⌄
Copies object references instead of actual data.
34. What is deep copy?⌄
Copies actual data and allocates new memory.
35. What is const correctness?⌄
Ensuring data is not modified unintentionally.
36. What is friend function?⌄
Function allowed to access private members.
37. What is diamond problem?⌄
Ambiguity caused by multiple inheritance.
38. What is virtual destructor?⌄
Ensures proper cleanup of derived objects.
39. What is type casting?⌄
Converting one data type to another.
40. static_cast vs dynamic_cast?⌄
static_cast is compile-time; dynamic_cast is runtime-checked.
41. What is const_cast?⌄
Adds or removes const qualifier.
42. What is reinterpret_cast?⌄
Performs low-level type conversion.
43. What is constexpr?⌄
Evaluates expressions at compile time.
44. What is noexcept?⌄
Specifies that a function does not throw exceptions.
45. What is inline function?⌄
Expands function code at compile time.
46. What is static keyword?⌄
Preserves value and limits scope.
47. What is extern keyword?⌄
Refers to a variable defined in another file.
48. What is infinite loop?⌄
A loop that never terminates.
49. What is main() function?⌄
The entry point of a C++ program.
50. Call by value vs call by reference?⌄
Call by value passes copies; call by reference passes memory addresses.