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

C++ Viva Questions

The document is a comprehensive guide on Object-Oriented Programming (OOP) concepts in C++, covering key topics such as classes, objects, inheritance types, encapsulation, abstraction, and various functions including constructors and destructors. It also explains access specifiers, storage classes, operator overloading, exception handling, and the differences between structs and classes. Additionally, it addresses function parameters, recursion, namespaces, and friend functions, providing a solid overview for understanding OOP in C++.

Uploaded by

Garima Agrawal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

C++ Viva Questions

The document is a comprehensive guide on Object-Oriented Programming (OOP) concepts in C++, covering key topics such as classes, objects, inheritance types, encapsulation, abstraction, and various functions including constructors and destructors. It also explains access specifiers, storage classes, operator overloading, exception handling, and the differences between structs and classes. Additionally, it addresses function parameters, recursion, namespaces, and friend functions, providing a solid overview for understanding OOP in C++.

Uploaded by

Garima Agrawal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Viva Question of OOPS C++

1. What is the full form of OOPS?


Object Oriented Programming System.
2. What is a class?
Class is a blue print which reflects the entities attributes and actions. Technically
defining a class is designing an user defined data type.
3. What is an object?
An instance of the class is called as object.
4. List the types of inheritance supported in C++.
Single, Multilevel, Multiple, Hierarchical and Hybrid.
5. What is the role of protected access specifier?
If a class member is protected then it is accessible in the inherited class. However,
outside the both the private and protected members are not accessible.
6. What is encapsulation?
The process of binding the data and the functions acting on the data together in an
entity (class) called as encapsulation.
7. What is abstraction?
Abstraction refers to hiding the internal implementation and exhibiting only the
necessary details.
8. What is inheritance?
Inheritance is the process of acquiring the properties of the exiting class into the new
class. The existing class is called as base/parent class and the inherited class is called
as derived/child class.
9. What is an inline function?
A function prefixed with the keyword inline before the function definition is called as
inline function. The inline functions are faster in execution when compared to normal
functions as the compiler treats inline functions as macros.
10. What is a storage class?
Storage class specifies the life or scope of symbols such as variable or functions.
11. Mention the storage classes names in C++.
The following are storage classes supported in C++

auto, static, extern, register and mutable


12. What is a pure virtual function?
A virtual function with no function body and assigned with a value zero is called as
pure virtual function.

1
13. What is an abstract class in C++?
A class with at least one pure virtual function is called as abstract class. We cannot
instantiate an abstract class.
14. What is role of static keyword on class member variable?
A static variable does exit though the objects for the respective class are not created.
Static member variable share a common memory across all the objects created for the
respective class. A static member variable can be referred using the class name itself.
15. Explain the static member function.
A static member function can be invoked using the class name as it exits before class
objects comes into existence. It can access only static members of the class.
Name the data type which can be used to store wide characters in C++.
wchar_t
16. What are/is the operator/operators used to access the class members?
Dot (.) and Arrow ( -> )
17. Can we initialize a class/structure member variable as soon as the same is
defined?
No, Defining a class/structure is just a type definition and will not allocated memory for
the same.
18. What is the data type to store the Boolean value?
bool, is the new primitive data type introduced in C++ language.
19. What is function overloading?
Defining several functions with the same name with unique list of parameters is called
as function overloading.
20. What is operator overloading?
Defining a new job for the existing operator w.r.t the class objects is called as operator
overloading.
21. Name the default standard streams in C++.
cin, cout, cerr and clog.
22. Which access specifier/s can help to achieve data hiding in C++?
Private & Protected.
23. When a class member is defined outside the class, which operator can be
used to associate the function definition to a particular class?
Scope resolution operator (::)
24. What is a destructor? Can it be overloaded?
A destructor is the member function of the class which is having the same name as the
class name and prefixed with tilde (~) symbol. It gets executed automatically w.r.t the

2
object as soon as the object loses its scope. It cannot be overloaded and the only form
is without the parameters.
25. What is a constructor?
A constructor is the member function of the class which is having the same as the
class name and gets executed automatically as soon as the object for the respective
class is created.
26. What is a default constructor? Can we provide one for our class?
Every class does have a constructor provided by the compiler if the programmer
doesn’t provides one and known as default constructor. A programmer provided
constructor with no parameters is called as default constructor. In such case compiler
doesn’t provides the constructor.
27. Which operator can be used in C++ to allocate dynamic memory?
‘new’ is the operator can be used for the same.
28. What is a friend function?
A function which is not a member of the class but still can access all the member of
the class is called so. To make it happen we need to declare within the required class
following the keyword ‘friend’.
29. What is a copy constructor?
A copy constructor is the constructor which take same class object reference as the
parameter. It gets automatically invoked as soon as the object is initialized with
another object of the same class at the time of its creation.
30. Does C++ supports exception handling? If so what are the keywords involved
in achieving the same.
C++ does supports exception handling. try, catch & throw are keyword used for the
same.
31. Explain the pointer – this.
This, is the pointer variable of the compiler which always holds the current active
object’s address.
32. What is the difference between the keywords struct and class in C++?
By default the members of struct are public and by default the members of the class
are private.
33. What is the block scope variable in C++?
A variable whose scope is applicable only within a block is said so. Also a variable in
C++ can be declared anywhere within the block.
34. What is the role of the file opening mode ios::trunk?
If the file already exists, its content will be truncated before opening the file.

3
35. What is the scope resolution operator?
The scope resolution operator is used to

 Resolve the scope of global variables.


 To associate function definition to a class if the function is defined outside the
class.
36. What is a namespace?
A namespace is the logical division of the code which can be used to resolve the name
conflict of the identifiers by placing them under different name space.
37. Can a program be compiled without main() function?
Yes, it can be but cannot be executed, as the execution requires main() function
definition.
38. Where an automatic variable is stored?
Every local variable by default being an auto variable is stored in stack memory
39. What is a token?
A C++ program consists of various tokens and a token is either a keyword, an
identifier, a constant, a string literal, or a symbol.
40. What is a preprocessor?
Preprocessor is a directive to the compiler to perform certain things before the actual
compilation process begins.
41. What are the different ways of passing parameters to the functions? Which to
use when?
 Call by value − We send only values to the function as parameters. We choose
this if we do not want the actual parameters to be modified with formal
parameters but just used.

 Call by address − We send address of the actual parameters instead of values.


We choose this if we do want the actual parameters to be modified with formal
parameters.

 Call by reference − The actual parameters are received with the C++ new
reference variables as formal parameters. We choose this if we do want the
actual parameters to be modified with formal parameters.
42. What is reminder for 5.0 % 2?
Error, It is invalid that either of the operands for the modulus operator (%) is a real
number.
43. How can we refer to the global variable if the local and the global variable
names are same?

4
We can apply scope resolution operator (::) to the for the scope of global variable.
44. What is recursion?
Function calling itself is called as recursion.
45. What is the maximum length of an identifier?
Ideally it is 32 characters and also implementation dependent.
46. What is the default function call method?
By default the functions are called by value.
47. What are available mode of inheritance to inherit one class from another?
Public, private & protected
48. Does an abstract class in C++ need to hold all pure virtual functions?
Not necessarily, a class having at least one pure virtual function is abstract class too.
49. Is it legal to assign a base class object to a derived class pointer?
No, it will be error as the compiler fails to do conversion.
50. Are the exceptions and error same?
No, exceptions can be handled whereas program cannot resolve errors.
51. Can we create and empty class? If so what would be the size of such object.
We can create an empty class and the object size will be 1.
52. What is ‘std’?
Default namespace defined by C++.
53. What is ‘cout’?
cout is the object of ostream class. The stream ‘cout’ is by default connected to
console output device.
54. What is ‘cin’?
cin is the object of istream class. The stream ‘cin’ is by default connected to console
input device.
55. What is the use of the keyword ‘using’?
It is used to specify the namespace being used in.
56. If a pointer declared for a class, which operator can be used to access its
class members?
Arrow (->) operator can be used for the same
57. What is difference between including the header file with-in angular braces < >
and double quotes “ “
If a header file is included with in < > then the compiler searches for the particular
header file only with in the built in include path. If a header file is included with in “ “,
then the compiler searches for the particular header file first in the current working
directory, if not found then in the built in include path

5
58. What is the difference between actual and formal parameters?
The parameters sent to the function at calling end are called as actual parameters
while at the receiving of the function definition called as formal parameters.
59. What is the difference between variable declaration and variable definition?
Declaration associates type to the variable whereas definition gives the value to the
variable.
60. What is a friend class?
A class members can gain accessibility over other class member by placing the class
declaration prefixed with the keyword ‘friend’ in the destination class.

You might also like