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

C++_Viva_Questions

The document provides a set of C++ programming viva questions and answers, covering fundamental concepts such as object-oriented programming, data types, control structures, functions, inheritance, polymorphism, pointers, file handling, exception handling, templates, and the Standard Template Library (STL). It highlights the differences between C and C++, explains key programming principles, and defines important terms and functionalities in C++. This resource serves as a study guide for understanding core C++ programming concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

C++_Viva_Questions

The document provides a set of C++ programming viva questions and answers, covering fundamental concepts such as object-oriented programming, data types, control structures, functions, inheritance, polymorphism, pointers, file handling, exception handling, templates, and the Standard Template Library (STL). It highlights the differences between C and C++, explains key programming principles, and defines important terms and functionalities in C++. This resource serves as a study guide for understanding core C++ programming concepts.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C++ Programming Viva Questions and Answers

1. What is C++? How does it differ from C?

C++ is an object-oriented programming language that extends C by adding features like classes,

objects, and inheritance. C focuses on procedural programming, while C++ supports both

procedural and object-oriented programming paradigms.

2. Explain the concept of Object-Oriented Programming (OOP).

OOP is a programming paradigm based on the concept of objects, which contain data in the form of

fields and methods. Key principles include encapsulation, inheritance, polymorphism, and

abstraction.

3. What are the basic data types in C++?

The basic data types in C++ include int, float, double, char, bool, and void. They are used to declare

variables of different types.

4. Define a class and an object.

A class is a blueprint for creating objects. It defines the properties and behaviors of the object. An

object is an instance of a class.

5. What is a namespace? Why is it used?

A namespace is a container for identifiers to avoid naming conflicts. It allows organizing code into

logical groups.

6. Describe the different types of control structures in C++.

Control structures include sequential, selection (if, switch), and iteration (for, while, do-while).

7. How do 'for', 'while', and 'do-while' loops differ?

The 'for' loop is used when the number of iterations is known. 'While' loop is used for

condition-based iteration. 'Do-while' executes the block at least once, as the condition is checked
after execution.

8. What is a function in C++?

A function is a block of code that performs a specific task. Functions promote code reuse and

modular programming.

9. Explain the difference between call by value and call by reference.

Call by value copies the actual value of arguments into formal parameters, while call by reference

passes the address of arguments, allowing modification of the original value.

10. What are inline functions? When are they used?

Inline functions are defined with the 'inline' keyword. They reduce function call overhead by

replacing the function call with the actual code.

11. What is a constructor? What are its types?

A constructor is a special function used to initialize objects. Types include default, parameterized,

and copy constructors.

12. Define a destructor. When is it invoked?

A destructor is a special function used to destroy objects and release resources. It is invoked

automatically when an object goes out of scope.

13. What is inheritance in C++?

Inheritance allows a class (child) to acquire the properties and behaviors of another class (parent),

promoting code reuse.

14. Differentiate between single, multiple, and multilevel inheritance.

Single inheritance involves one base and one derived class. Multiple inheritance involves multiple

base classes. Multilevel inheritance involves a chain of inheritance.

15. Define polymorphism. What are its types?


Polymorphism means 'many forms'. It allows methods or operators to behave differently based on

the context. Types include compile-time (function overloading, operator overloading) and runtime

polymorphism (virtual functions).

16. What is a pointer? How is it different from a reference?

A pointer is a variable that stores the memory address of another variable. A reference is an alias for

an existing variable and cannot be null.

17. How does file handling work in C++?

File handling allows reading from and writing to files using streams. The ifstream and ofstream

classes are used for input and output operations, respectively.

18. What is exception handling? Why is it important?

Exception handling manages runtime errors using try, catch, and throw keywords, ensuring the

program doesn't crash unexpectedly.

19. What are templates in C++?

Templates enable writing generic and reusable code by allowing functions and classes to operate

on different data types.

20. What is the Standard Template Library (STL)?

STL is a collection of pre-defined classes and functions for data structures, algorithms, and iterators.

You might also like