Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

C++ MODEL PRACTICAL VIVA QUESTION AND ANSWERS

1.FUNCTION OVERLOAING: A program contains more than one function and each
function has a same function name and having different parameters.

Ex: int add(int a,int b);

float add(float a,float b);

2.DEFAULT ARGUMENT: A default argument is a value in the function declaration


automatically assigned by the compiler if the calling function does not pass any value to
that argument.

3.INLINE FUNCTION: An inline function is a function that is expanded in line when it is


called.

4.CLASS: a class describes the contents of the objects that belong to it

5.OBJECT: an object is an element (or instance) of a class; objects have the behaviors of
their class.

6.HOW TO PASS AN OBJECT TO FUNCTION: We can pass class's objects as arguments and
also return them from a function.

EX: function_name(object_name);

7. COMPLEX NUMBERS are the numbers that are expressed in the form of a+ib where, a,b
are real numbers and 'i' is an imaginary number called “iota”. The value of i = (√-1). For
example, 2+3i is a complex number, where 2 is a real number (Re) and 3i is an imaginary
number (Im).

8. A FRIEND FUNCTION is a function that isn't a member of a class but has access to the
class's private and protected members.

9. The ‘this’ pointer is passed as a hidden argument to all nonstatic member function
calls and is available as a local variable within the body of all nonstatic functions.

this->x = x; // The 'this' pointer is used to retrieve the object's x


10. CONSTRUCTOR:Constructor helps to initialize the object of a class. It is declared as
className( arguments )
{
Constructor’s Body
}.

11. DESTRUCTOR: Whereas destructor is used to destroy the instances. Whereas it is


declared as

~ className( no arguments )

}.

12.OPERATOR OVERLOAING: the ability to provide the operators with a special meaning
for a data type, this ability is known as operator overloading.

13.UNARY OPERATOR OVERLOAING: Unary operators are the operators that perform
operations on a single operand to produce a new value.
1. Unary minus ( – )
2. Increment ( ++ )
3. Decrement ( - - )

14. BINARY OPERATOR OVERLOADING: the overloading of an operator operating on


two operands.

15.OPERATORS THAT CANNOT BE OVERLOADED:


1) Scope Resolution Operator (::)
2) Ternary or Conditional Operator (?:)
3) Member Access or Dot operator (.)
4) Pointer-to-member Operator (.*)
5) Object size Operator (sizeof)

16. INHERITANCE: The capability of a class to derive properties and characteristics from
another class is called Inheritance.

17. SINGLE INHERITANCE: In single inheritance, a class is allowed to inherit from only
one class. i.e. one subclass is inherited by one base class only.

18. MULTIPLE INHERITANCE: Multiple Inheritance is a feature of C++ where a class can
inherit from more than one class. i.e one subclass is inherited from more than one base
class.
19. MULTILEVEL INHERITANCE: In this type of inheritance, a derived class is created
from another derived class.

20. HIERARCHICAL INHERITANCE: In this type of inheritance, more than one subclass is
inherited from a single base class. i.e. more than one derived class is created from a single
base class.

21. HYBRID (VIRTUAL) INHERITANCE: Hybrid Inheritance is implemented by


combining more than one type of inheritance.

22. A VIRTUAL FUNCTION (also known as virtual methods) is a member function that is
declared within a base class and is re-defined (overridden) by a derived class.
 Functions are declared with a virtual keyword in a base class.

23. FILE HANDLING IN C++ is a mechanism to create and perform read/write operations
on a file.

#include <fstream>
<fstream> includes two classes for file handling:
 ifstream - to read from a file.
 ofstream - to create/open and write to a file.

24. // OPENING A TEXT FILE FOR WRITING


ofstream my_file("example.txt");

// CLOSE THE FILE


my_file.close();

25.READ FILE:
ifstream my_file("example.txt");

while (!my_file.eof()) {
getline(my_file, line); }

26.WRITE FILES:
ofstream my_file("example.txt"); my_file << "Line 1" << endl;
27. COMMAND-LINE ARGUMENTS: are arguments that are passed to a program when it
is executed from the command line. to pass command-line arguments, we typically define
main() with two arguments,

int main(int argc, char *argv[])

variable argc (ARGument Count)- number of command-line arguments

array argv (ARGument Vector)- list of command-line arguments.

28.HOW TO RUN COMMANDLINE ARGUMENT:


C:\TURBOC3\SOURCE>commandargu.exe 12 22 15

29.TEMPLATE: is to pass the data type as a parameter so that we don’t need to write the
same code for different data types.

30.CLASS TEMPLATE: class templates are useful when a class defines something that is
independent of the data type. template<class T1,class T2>

31.FUNCTION TEMPLATE: a generic function that can be used for different data types.
Examples of function templates are sort(), max(), min()

template<class T>

T max(T a,T b)

32.EXCEPTION: An exception is an unexpected problem that arises during the execution


of a program

33. Why do we need exception Handling?

Separate Error code from Normal code to help us understand errors easily.

34. How to implement exception handling in C++?

try{ } and catch( ){ }

You might also like