0% found this document useful (0 votes)
137 views3 pages

C++ Lab Viva Questions and Answers

The document provides a compilation of C++ lab viva questions and answers covering fundamental concepts such as data types, object-oriented programming principles, functions, memory management, polymorphism, templates, exception handling, and STL. Key topics include the differences between C and C++, the role of constructors and destructors, and the use of pointers. It also touches on miscellaneous concepts like friend functions, recursion, and the distinction between structs and classes.
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)
137 views3 pages

C++ Lab Viva Questions and Answers

The document provides a compilation of C++ lab viva questions and answers covering fundamental concepts such as data types, object-oriented programming principles, functions, memory management, polymorphism, templates, exception handling, and STL. Key topics include the differences between C and C++, the role of constructors and destructors, and the use of pointers. It also touches on miscellaneous concepts like friend functions, recursion, and the distinction between structs and classes.
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/ 3

C++ Lab Viva Questions and Answers

Basics of C++
Q: What is C++?

A: C++ is a general-purpose, object-oriented programming language developed by Bjarne

Stroustrup as an extension of C.

Q: What are the basic data types in C++?

A: int, float, double, char, bool, void

Q: What is the difference between C and C++?

A: C is procedural; C++ supports object-oriented programming (OOP). C++ has features like

classes, objects, inheritance, polymorphism.

Q: What is a namespace in C++?

A: A namespace is used to avoid naming conflicts by grouping entities like classes, objects, and

functions under a name.

Q: What is iostream?

A: A header file that allows input and output using cin and cout.

OOP Concepts
Q: What is Object-Oriented Programming (OOP)?

A: A programming paradigm based on objects and classes. Principles include Encapsulation,

Abstraction, Inheritance, and Polymorphism.

Q: What is a class and an object?

A: Class: Blueprint or template. Object: Instance of a class.

Q: What is encapsulation?

A: Binding data and methods together in a class and restricting access using access specifiers.

Q: What are access specifiers?


A: private, public, protected.

Q: What is inheritance?

A: Process where one class (derived) inherits features from another (base). Types: Single, Multiple,

Multilevel, Hierarchical, Hybrid.

Functions and Constructors


Q: What is a constructor?

A: A special function automatically called when an object is created.

Q: Types of constructors?

A: Default, Parameterized, Copy constructor.

Q: What is a destructor?

A: A special function called when an object is destroyed to free resources.

Q: What is function overloading?

A: Same function name with different parameters.

Q: What is operator overloading?

A: Using operators like +, - with user-defined types (classes).

Memory & Pointers


Q: What is a pointer in C++?

A: A variable that stores the address of another variable.

Q: What is new and delete?

A: new allocates memory, delete deallocates memory.

Q: What is the difference between malloc() and new?

A: malloc() is C-style; new is C++-style and calls constructors.

Polymorphism and Virtual Functions


Q: What is polymorphism?

A: Allows functions to behave differently based on context. Types: Compile-time and Run-time.
Q: What is a virtual function?

A: A function in the base class that can be overridden in a derived class.

Q: What is a pure virtual function?

A: A function with no definition; makes the class abstract.

Templates, Exception Handling, and STL


Q: What are templates in C++?

A: Allow functions or classes to operate with generic types.

Q: What is exception handling?

A: Handles runtime errors using try, catch, and throw.

Q: What is STL in C++?

A: Standard Template Library includes ready-to-use classes like vectors, stacks, queues, etc.

Miscellaneous
Q: What is the difference between struct and class?

A: In struct, members are public by default; in class, they are private by default.

Q: What is a friend function?

A: A function that can access private members of a class.

Q: What is the use of this pointer?

A: Points to the current object of the class.

Q: What is recursion?

A: A function that calls itself.

You might also like