Q: What is variable?
A: A variable is a name given to a memory location that stores data. It can hold different values
during program execution.
Q: What is recursion?
A: Recursion is a process where a function calls itself to solve a smaller part of a bigger problem.
Q: What is destructor?
A: A destructor is a special function in a class that is automatically called when an object is
destroyed to free resources.
Q: What is this pointer?
A: `this` pointer is an internal pointer in C++ that points to the current object of a class.
Q: What is friend function?
A: A friend function can access the private and protected members of a class even though it is not a
member of that class.
Q: What is overriding?
A: Overriding means defining a function in a derived class with the same name and arguments as in
the base class to provide a new definition.
Q: What is iostreams?
A: `iostream` is a C++ library used for input and output operations using `cin`, `cout`, etc.
Q: What is iterators?
A: Iterators are objects used to point to elements in containers like arrays or vectors and allow easy
traversal.
Q: What is class and object?
A: A class is a blueprint for creating objects. An object is an instance of a class.
Q: List data type in C++.
A: Common data types: `int`, `float`, `char`, `double`, `bool`, `void`.
Q: Define pointer.
A: A pointer is a variable that stores the memory address of another variable.
Q: What is object copying?
A: Object copying means creating a new object as an exact copy of another, usually using a copy
constructor.
Q: Discuss static functions.
A: Static functions belong to the class, not to objects. They can be called without creating an object.
Q: Explain namespace.
A: A namespace is used to group identifiers (like functions, classes) and avoid name conflicts.
Q: Describe derived class with an example.
A: A derived class inherits properties from a base class.
Example:
class Animal { };
class Dog : public Animal { };
Q: What is private inheritance?
A: In private inheritance, public and protected members of the base class become private in the
derived class.
Q: What is friend function?
A: A friend function can access private and protected members of a class, even though it is not a
member.
Q: What is virtual function?
A: A virtual function allows a function to be overridden in a derived class and supports runtime
polymorphism.
Q: What is namespace in C++?
A: A namespace groups code to avoid name conflicts.
Q: Difference between procedural language and object-oriented approach.
A: - Procedural: Focus on functions, step-by-step tasks.
- OOP: Focus on objects, classes, and data.
Q: What is object copying?
A: Making a new object with the same values as another object using a copy constructor.
Q: What is abstract class?
A: An abstract class has at least one pure virtual function and cannot be instantiated.
Q: What is polymorphism?
A: Polymorphism means having many forms. It allows the same function name to behave differently
based on context.
Q: What is iterators?
A: Iterators are used to access elements in containers like arrays and lists.
Q: Discuss static functions and its uses in C++.
A: Static functions belong to the class. They are used when we don't need object-specific data and
want a single function for all objects.
Q: Describe two major applications of abstraction.
A: 1. Hiding complex logic (e.g., in ATM software).
2. Providing simple interfaces (e.g., car driving interface).
Q: Explain new with an example in C++.
A: `new` is used to allocate memory dynamically.
Example: int* p = new int;
Q: Discuss derived class in C++.
A: A derived class is created from a base class and inherits its members. It can also have additional
features.
Q: Describe iostreams in C++ in few lines.
A: `iostream` is a header file that provides input/output features using objects like `cin`, `cout`, and
`cerr`.
Q: Differentiate between private and protected in C++.
A: - Private: Accessible only within the class.
- Protected: Accessible within class and derived classes.
Q: Write the use and advantage of recursion in C++
A: Recursion simplifies code, especially for problems like factorial or tree traversal, by breaking them
into smaller tasks.
Q: Explain user defined type in C++.
A: User-defined types are custom data types created using classes, structs, unions, or enums.
Q: What is data type in C++?
A: A data type defines the kind of data a variable can hold, like `int` for numbers or `char` for
characters.
Q: What is flow control?
A: Flow control refers to the order in which statements are executed, controlled using `if`, `while`,
`for`, etc.
Q: What is iterators?
A: Objects used to access elements in a container sequentially.
Q: What is object copying?
A: Creating a copy of an object, usually via a copy constructor.
Q: Explain derived class and base class.
A: A base class provides properties, and a derived class inherits them.
Example:
class A { };
class B : public A { };
Q: What is abstract class?
A: A class with at least one pure virtual function. It cannot be used to create objects.
Q: What is polymorphism?
A: It allows functions to behave differently based on the object calling them.
Q: What is namespace in C++?
A: Used to group functions and variables to prevent naming conflicts.