Skip to content
- Home
- Blog
- Most 100 C++ Language Interview Question & Answer | CodeBaaj |
C++ Interview Questions & Answers (Top 100)
Basics of C++
- What is C++?
C++ is an object-oriented programming language developed by Bjarne Stroustrup as an extension of C.
- Is C++ a compiled language?
Yes, C++ is a compiled language.
- Who developed C++?
Bjarne Stroustrup.
- What is OOP?
OOP (Object-Oriented Programming) is a programming paradigm based on objects and classes.
- What are the main features of C++?
OOP, portability, performance, memory management, STL.
- What is a class?
A class is a blueprint for creating objects.
- What is an object?
An object is an instance of a class.
- What is namespace?
Namespace is used to avoid name conflicts in large programs.
- What is
std?
std is the standard namespace in C++.
- What is
main() function?
It is the entry point of a C++ program.
Data Types & Variables
- What are primitive data types in C++?
int, float, double, char, bool.
- What is
sizeof() operator?
It returns the size of a data type in bytes.
- Difference between
float and double?
double has more precision than float.
- What is a constant?
A variable whose value cannot be changed.
- How to declare a constant?
Using const keyword.
Operators
- What are operators?
Symbols used to perform operations.
- Types of operators in C++?
Arithmetic, Relational, Logical, Assignment, Bitwise.
- What is ternary operator?
condition ? true : false
- What is increment operator?
Increases value by 1 (++).
- Difference between
++i and i++?
++i increments first, i++ increments later.
Control Statements
- What is
if statement?
Executes code if condition is true.
- What is
switch statement?
Selects execution paths based on value.
- Difference between
for and while loop?
for is entry-controlled, while checks condition first.
- What is
do-while loop?
Executes at least once.
- What is
break?
Terminates loop or switch.
Functions
- What is a function?
A block of code that performs a task.
- What is function overloading?
Same function name with different parameters.
- What is recursion?
Function calling itself.
- What is inline function?
Expands function code at compile time.
- What is default argument?
A predefined value for function parameter.
Arrays & Strings
- What is an array?
Collection of same data type elements.
- What is a string in C++?
Sequence of characters.
- Difference between array and vector?
Vector is dynamic, array is static.
- What is
strlen()?
Returns string length.
- What is multidimensional array?
Array with more than one dimension.
Pointers & References
- What is a pointer?
Variable that stores address of another variable.
- What is
NULL pointer?
Pointer that points to nothing.
- What is reference variable?
Alias of another variable.
- Difference between pointer and reference?
Pointer can be null, reference cannot.
- What is dangling pointer?
Pointer pointing to deleted memory.
OOP Concepts
- What is encapsulation?
Binding data and functions together.
- What is inheritance?
Acquiring properties of another class.
- What is polymorphism?
Same function behaves differently.
- What is abstraction?
Hiding implementation details.
- Types of inheritance?
Single, Multiple, Multilevel, Hierarchical, Hybrid.
Constructors & Destructors
- What is constructor?
Special function called when object is created.
- What is destructor?
Called when object is destroyed.
- Types of constructors?
Default, Parameterized, Copy.
- What is copy constructor?
Initializes object using another object.
- Can constructor be virtual?
No.
Virtual Functions
- What is virtual function?
Function overridden in derived class.
- What is runtime polymorphism?
Achieved using virtual functions.
- What is
virtual keyword?
Enables dynamic binding.
- What is base class?
Parent class.
- What is derived class?
Child class.
Memory Management
- What is
new keyword?
Allocates memory dynamically.
- What is
delete keyword?
Frees allocated memory.
- What is memory leak?
Memory not released after use.
- Stack vs Heap?
Stack is automatic, Heap is dynamic.
- What is dynamic memory allocation?
Allocating memory at runtime.
File Handling
- What is file handling?
Reading/writing data to files.
- File handling classes?
ifstream, ofstream, fstream.
- What is
ifstream?
Reads from file.
- What is
ofstream?
Writes to file.
- What is
fstream?
Reads and writes.
STL (Standard Template Library)
- What is STL?
Collection of templates.
- Components of STL?
Containers, Algorithms, Iterators.
- What is vector?
Dynamic array.
- What is map?
Stores key-value pairs.
- What is iterator?
Used to traverse containers.
Exception Handling
- What is exception?
Runtime error.
- Keywords for exception handling?
try, catch, throw.
- What is try block?
Code that may cause exception.
- What is catch block?
Handles exception.
- What is throw?
Throws exception manually.
Miscellaneous
- What is header file?
Contains declarations.
- Difference between C and C++?
C is procedural, C++ is OOP.
- What is template?
Generic programming feature.
- What is
typedef?
Creates alias for data types.
- What is
mutable keyword?
Allows modification in const object.
Advanced Concepts
- What is
const function?
Cannot modify object.
- What is
friend function?
Access private members.
- What is
static variable?
Retains value between calls.
- What is
volatile keyword?
Prevents optimization.
- What is
this pointer?
Points to current object.
Interview Practical Questions
- Can main() be overloaded?
No.
- Can we have multiple inheritance?
Yes.
- Can destructor be virtual?
Yes.
- What is pure virtual function?
Virtual function with =0.
- What is abstract class?
Class with pure virtual function.
Final Set
- What is operator overloading?
Redefining operators.
- What is inline namespace?
Namespace treated as parent.
- What is smart pointer?
Automatically manages memory.
- Types of smart pointers?
unique_ptr, shared_ptr, weak_ptr.
- What is lambda function?
Anonymous function.
- What is constexpr?
Compile-time constant.
- What is auto keyword?
Automatic type deduction.
- What is nullptr?
Type-safe null pointer.
- What is range-based for loop?
Loop for containers.
- Why C++ is fast?
Close to hardware, compiled, manual memory control.