0% found this document useful (0 votes)
16 views4 pages

C++ Short Answers 2-4 Lines

The document provides definitions and explanations of various C++ programming concepts, including variables, recursion, destructors, friend functions, and more. It covers topics such as class and object relationships, data types, inheritance, polymorphism, and namespaces. Additionally, it highlights the differences between procedural and object-oriented programming approaches.

Uploaded by

valam1g0kev3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

C++ Short Answers 2-4 Lines

The document provides definitions and explanations of various C++ programming concepts, including variables, recursion, destructors, friend functions, and more. It covers topics such as class and object relationships, data types, inheritance, polymorphism, and namespaces. Additionally, it highlights the differences between procedural and object-oriented programming approaches.

Uploaded by

valam1g0kev3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Q: What is variable?

A: A variable is a named memory location used to store data. Its value can change during program

execution.

Q: What is recursion?

A: Recursion is a method where a function calls itself to solve a smaller part of a problem until a

base condition is met.

Q: What is destructor?

A: A destructor is a special class function called automatically when an object is destroyed, used to

free resources.

Q: What is this pointer?

A: `this` pointer refers to the current object of a class and is used to access its members.

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 of that class.

Q: What is overriding?

A: Overriding means redefining a base class function in a derived class using the same signature.

Q: What is iostreams?

A: `iostream` is a C++ library used for input/output operations, mainly through `cin`, `cout`, `cerr`,

etc.

Q: What is iterators?

A: Iterators are objects used to access and traverse elements in containers like arrays, lists, and

vectors.

Q: What is class and object?

A: A class is a blueprint for creating objects. An object is an instance of a class containing data and

functions.

Q: List data type in C++.


A: Common data types: int, float, char, double, bool, and void.

Q: Define pointer.

A: A pointer is a variable that stores the memory address of another variable.

Q: What is object copying?

A: It refers to creating a new object with the same values as an existing object, usually using a copy

constructor.

Q: Discuss static functions.

A: Static functions belong to the class, not instances. They are called using the class name and do

not access instance members.

Q: Explain namespace.

A: A namespace groups identifiers like classes and functions to avoid naming conflicts.

Q: Describe derived class with an example.

A: A derived class inherits from a base class.

Example:

class A { };

class B : public A { };

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: It can access all members of a class, even private ones, despite not being a class member.

Q: What is virtual function?

A: A virtual function is defined in the base class and overridden in derived classes for runtime

polymorphism.

Q: What is namespace in C++?

A: Namespaces are used to organize code and prevent name conflicts in large projects.
Q: Difference between procedural language and object-oriented approach.

A: Procedural languages focus on functions; OOP focuses on objects. OOP supports inheritance

and encapsulation.

Q: What is object copying?

A: Copying an object creates a new one with the same values, often via 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 allows functions or objects to behave differently based on the context or data

types.

Q: What is iterators?

A: Iterators provide a way to access elements in a container sequentially without exposing

underlying details.

Q: Discuss static functions and its uses in C++.

A: Static functions can be called without objects. They're useful when the function doesn't need

object data.

Q: Describe two major applications of abstraction.

A: Abstraction hides internal details. Applications: ATM interface, vehicle controls.

Q: Explain new with an example in C++.

A: `new` dynamically allocates memory.

Example: int* p = new int;

Q: Discuss derived class in C++.

A: A derived class extends the base class by inheriting its properties and adding new ones.

Q: Describe iostreams in C++ in few lines.

A: `iostream` handles standard input and output through objects like `cin`, `cout`, and `cerr`.

Q: Differentiate between private and protected in C++.


A: Private members are accessible only in the class. Protected members are also accessible in

derived classes.

Q: Write the use and advantage of recursion in C++

A: Recursion simplifies complex problems like tree traversal and reduces code size.

Q: Explain user defined type in C++.

A: User-defined types like class, struct, enum allow defining custom data structures.

Q: What is data type in C++?

A: A data type defines what type of value a variable holds, such as int, char, float.

Q: What is flow control?

A: Flow control manages the order of execution using conditions and loops like if, while, and for.

Q: What is iterators?

A: Iterators are tools to navigate containers like vectors and lists in C++.

Q: What is object copying?

A: It creates a duplicate object with the same state as another.

Q: Explain derived class and base class.

A: A base class provides members; a derived class inherits and extends them.

Q: What is abstract class?

A: A class with at least one pure virtual function, used as a base class.

Q: What is polymorphism?

A: Allows the same function to act differently for different classes or data.

Q: What is namespace in C++?

A: A feature to group related code and avoid name clashes.

You might also like