C++_Viva_Questions
C++_Viva_Questions
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
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.
The basic data types in C++ include int, float, double, char, bool, and void. They are used to declare
A class is a blueprint for creating objects. It defines the properties and behaviors of the object. An
A namespace is a container for identifiers to avoid naming conflicts. It allows organizing code into
logical groups.
Control structures include sequential, selection (if, switch), and iteration (for, while, do-while).
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.
A function is a block of code that performs a specific task. Functions promote code reuse and
modular programming.
Call by value copies the actual value of arguments into formal parameters, while call by reference
Inline functions are defined with the 'inline' keyword. They reduce function call overhead by
A constructor is a special function used to initialize objects. Types include default, parameterized,
A destructor is a special function used to destroy objects and release resources. It is invoked
Inheritance allows a class (child) to acquire the properties and behaviors of another class (parent),
Single inheritance involves one base and one derived class. Multiple inheritance involves multiple
the context. Types include compile-time (function overloading, operator overloading) and runtime
A pointer is a variable that stores the memory address of another variable. A reference is an alias for
File handling allows reading from and writing to files using streams. The ifstream and ofstream
Exception handling manages runtime errors using try, catch, and throw keywords, ensuring the
Templates enable writing generic and reusable code by allowing functions and classes to operate
STL is a collection of pre-defined classes and functions for data structures, algorithms, and iterators.