0% found this document useful (0 votes)
50 views

Top 25 C++ Programming Viva Questions

Top 25 c++ Programming Viva Questions

Uploaded by

Akash Deshmukhe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Top 25 C++ Programming Viva Questions

Top 25 c++ Programming Viva Questions

Uploaded by

Akash Deshmukhe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Basics of C++

1. What is C++?
C++ is an object-oriented programming language developed by Bjarne Stroustrup as
an extension of C. It supports procedural, object-oriented, and generic programming.

2. What are the key features of C++?

 Object-oriented programming (OOP)


 Support for function overloading and operator overloading
 Inline functions
 Exception handling
 Templates and STL (Standard Template Library)

3. What is the difference between C and C++?

 C: Procedural programming, lacks OOP features.


 C++: Supports OOP (classes, objects, inheritance, polymorphism).

2. Classes and Objects

4. What is a class in C++?


A class is a user-defined data type that represents a blueprint for creating objects. It
encapsulates data (attributes) and methods (functions).

5. What is an object?
An object is an instance of a class. It represents a real-world entity with properties and
behaviors defined by its class.

6. What is the difference between a class and a structure?

 Class: Members are private by default.


 Structure: Members are public by default.

3. OOP Concepts

7. What is encapsulation?
Encapsulation is the process of bundling data and functions into a single unit (class)
and restricting access using access specifiers (private, protected, public).

8. What is inheritance?
Inheritance allows a class (derived class) to acquire properties and behaviors of
another class (base class). Types include:
1. Single inheritance
2. Multiple inheritance
3. Multilevel inheritance
4. Hierarchical inheritance
5. Hybrid inheritance

9. What is polymorphism?
Polymorphism means "many forms." It allows a single function or operator to behave
differently based on context. Types:

1. Compile-time (e.g., function overloading, operator overloading)


2. Runtime (e.g., virtual functions)

10. What is abstraction?


Abstraction is the process of hiding implementation details and showing only
essential features through abstract classes or interfaces.

4. Functions

11. What is a constructor?


A constructor is a special function automatically invoked when an object is created. It
initializes the object. Types:

1. Default constructor
2. Parameterized constructor
3. Copy constructor

12. What is a destructor?


A destructor is a special function automatically invoked when an object is destroyed.
It is used to release resources and has the same name as the class, preceded by ~.

13. What is the difference between function overloading and overriding?

 Overloading: Same function name with different parameter lists (compile-time


polymorphism).
 Overriding: Redefining a base class function in a derived class (runtime polymorphism).

5. Memory Management

14. What is the purpose of new and delete?

 new: Allocates memory dynamically on the heap.


 delete: Deallocates memory allocated by new.
15. What is a pointer in C++?
A pointer is a variable that stores the memory address of another variable. It is used
for dynamic memory allocation and accessing array elements.

6. Operator Overloading

16. What is operator overloading?


Operator overloading allows operators to have user-defined meanings for custom
types (e.g., + for adding objects).

17. Can all operators be overloaded in C++?


No. Operators like ::, sizeof, . (member access), and .* (pointer-to-member access)
cannot be overloaded.

7. Templates and STL

18. What is a template?


A template is a blueprint for creating generic functions or classes that work with any
data type.

19. What is the STL in C++?


The Standard Template Library (STL) is a collection of pre-written classes and
functions for data structures (e.g., vector, list, map) and algorithms (e.g., sort,
search).

20. What is the difference between vector and array in C++?

 Array: Fixed size, static allocation.


 Vector: Dynamic size, grows/shrinks as needed.

8. Exception Handling

21. What is exception handling in C++?


Exception handling deals with runtime errors using try, catch, and throw blocks to
ensure the program continues running gracefully.

22. What is the difference between throw and throws?

 throw: Used to signal an exception in C++.


 throws: Not used in C++ (belongs to Java).
9. Access Specifiers and Namespaces

23. What are access specifiers in C++?


Access specifiers define the scope of class members:

 private: Accessible only within the class.


 protected: Accessible within the class and derived classes.
 public: Accessible from anywhere.

24. What is a namespace?


A namespace is a container for identifiers (variables, functions, classes) to avoid
naming conflicts. The std namespace contains standard C++ libraries.

10. Miscellaneous

25. What is the difference between cin and cout?

 cin: Used for input (e.g., cin >> variable;).


 cout: Used for output (e.g., cout << "Hello";).

You might also like