You are on page 1of 7

GENERAL C++ VIVA QUESTIONS

1.
P is an object pointer to a class student with data member mark.
Select the correct method of accessing from the following list:
a) P.mark
b) P::mark
c) P*mark
d) Pmark
2. Divya wrote a C++ function that allocates memory for100 integers using new operator.
Identify the problems that may arise if she does not use delete operator in it.
3. int a[5] = {10, 5, 18, 14, 16};
cout<<*(a+2);
What will be the output of the above code.
4. For a geometric system discuss the underlying OOP feature in the following operations
a) To combine data and function as a single unit
b) To define a function perimeter that finds perimeter for different shapes.
5. Identify the type of constructor invoked in the following cases.
a) An object is initialised with another object
b) An object is declared with initial values for the data members
6. Distinguish between
a.
b.
c.
d.
e.
f.
g.
h.
i.
j.
k.

Call by value and call by reference


Global variable and local variable
Class and object
Structure and Class
Data hiding and encapsulation
Simple variable & pointer variable
Constants and identifiers
Library functions and user defined functions
Structure & array
a and a
a=5 and a = = 5

Copy constructors are called in following cases:


a) when a function returns an object of that class by value
b) when the object of that class is passed by value as an argument to a function
c) when you construct an object based on another object of the same class
d) When compiler generates a temporary object
Diff. bet. Break and continue
A break statement results in the termination of the statement to which it applies (switch,
for, do, or while). A continue statement is used to end the current loop iteration and return
control to the loop statement.
For which statements does it make sense to use label?
The only statements for which it makes sense to use a label are those statements that can
enclose a break or continue statement.

Some Points to Consider


structures are a way of storing many different values in variables of potentially diff
types
under
under
the
same
name
2. classes and structures make program modular, easier to modify make things
compact
3. useful when a lot of data needs to be grouped together
4. struct Tag {?}struct example {Int x;}example ex; ex.x = 33; //accessing
variable
of
structure
5. members of a struct in C are by default public, in C++ private
6. unions like structs except they share memory ? allocates largest data type in
memory - like a giant storage: store one small OR one large but never both at the
same
time
7.
pointers
can
point
to
struct:
8. C++ can use class instead of struct (almost the same thing) - difference: C++
classes
can
include
functions
as
members
9. members can be declared as: private: members of a class are accessible only
from other members of their same class; protected: members are accessible from
members of their same class and friend classes and also members of their derived
classes; public: members are accessible from anywhere the class is visible
10. structs usually used for data only structures, classes for classes that have
procedures
and
member
functions.
What is inheritance?
Difference between Composition and Aggregation.
What is Polymorphism?
Is class an Object? Is object a class?
Comment: C++ "includes" behavior .
What is the use of Operator Overloading?
Every object has : state, behavior and identity explain.
Why constructors have no return type?
Why destructors invoke in reverse order?
What is role of constructor?
Why we need constructors?
What property of OOP is implemented in Constructors?
Can destructors be overloaded Yes/No & Why?
Can constructors be overloaded Yes/No & Why?
What is difference between default constructor and constructor
with default arguments?
16.
Can constructor use static variables?
17.
Does any value is returned by Constructors?
18.
Why the reference of an object is passed in copy constructor?
19.
When copy constructor is invoked?
20.
From the given conditions (1) Sample S1=S2; (2) S1=S2 ; When
copy constructor will invoke.
21.
if a derived class has no parameters for its constructor but a base
class has parameterized constructor , how the constructor for the derived class
would defined?
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.

EXPECTED VIVA questions(SOLVED)

1.

What is a class?

Class is concrete representation of an entity. It represents a group of objects, which hold similar attributes and
behavior. It provides Abstraction and Encapsulations. Classes are generally declared using the keyword class.
2. What is an Object? What is Object Oriented Programming?
Object represents/resembles a Physical/real entity. An object is simply something you can give a name.
Object Oriented Programming is a Style of programming that represents a program as a system of

3.

objects and enables code-reuse.


What is Encapsulation?
Encapsulation is binding of attributes and behaviors. Hiding the actual implementation and exposing the
functionality of any object. Encapsulation is the first step towards OOPS, is the procedure of covering
up of data and functions into a single unit (called class). Its main aim is to protect the data from out

4.

side world
What is Abstraction?
Hiding the complexity. It is a process of defining communication interface for the functionality and

5.

hiding rest of the things.


What is Overloading?
Adding a new method with the same name in same/derived class but with different number/types of

6.

parameters. It implements Polymorphism.


What is Inheritance?
It is a process in which properties of object of one class acquire the properties of object of another

7.

class.
What is an Abstract class?
An abstract class is a special kind of class that cannot be instantiated. It normally contains one or more

8.

abstract methods or abstract properties. It provides body to a class.


What is Polymorphism? And its type?

1.

What do you mean by iostream.h?

2.
3.

What is inheritance and its type?


What is the difference b/n public, private and protected?

Public: The data members and methods having public as access outside the class.
Protected: The data members and methods declared as protected will be accessible to the class
methods and the derived class methods only.
Private: These data members and methods will be accessibl not from objects created outside the
class.
4. What is a void return type?

A void return type indicates that a method does not return a value.
5.

What is the difference between a while statement and a do statement?


A while statement checks at the beginning of a loop to see whether the next loop iteration
should occur. A do statement checks at the end of a loop to see whether the next loop
iteration should occur..

6.

What is a nested class? Why can it be useful?


A nested class is a class enclosed within the scope of another class. For example: // Example
1: Nested class // class Outer Class {class Nested Class {// }; //...

7.

What is inline function?

Normally, a function call transfers the control from the calling program to the function and after
the execution of the program returns the control back to the calling program after the function call.
These concepts of function saved program space and memory space are used because the function
is stored only in one place and is only executed when it is called. This concept of function execution
may be time consuming since the registers and other processes must be saved before the function
gets called.
The extra time needed and the process of saving is valid for larger functions. If the function is short,
the programmer may wish to place the code of the function in the calling program in order for it to
be executed. This type of function is best handled by the inline function. In this situation, the
programmer may be wondering why not write the short code repeatedly inside the program
wherever needed instead of going for inline function? Although this could accomplish the task, the
problem lies in the loss of clarity of the program. If the programmer repeats the same code many
times, there will be a loss of clarity in the program. The alternative approach is to allow inline
functions to achieve the same purpose, with the concept of functions.
8.

What is preprocessor?
The preprocessor is used to modify your program according to the preprocessor directives
in your source code. Preprocessor directives (such as #define) give the preprocessor specific
instructions on how to modify your source code. The preprocessor reads in all of your
include files and the source code you are compiling and creates a preprocessed version of
your source code. This preprocessed version has all of its macros and constant symbols
replaced by their corresponding code and value assignments. If your source code contains
any conditional preprocessor directives (such as #if), the preprocessor evaluates the
condition and modifies your source code accordingly.
The preprocessor contains many features that are powerful to use, such as creating macros,
performing conditional compilation, inserting predefined environment variables into your
code, and turning compiler features on and off. For the professional programmer, in-depth
knowledge of the features of the preprocessor can be one of the keys to creating fast,
efficient programs.

9.

What is the difference between overloading and overriding?


Overloading - Two functions having same name and return
Type, but with different type and/or number of arguments.
Overriding - When a function of base class is re-defined in
the derived class.

10.

C++ Memory Management operators


The concept of arrays has a block of memory reserved. The disadvantage with the concept of
arrays is that the programmer must know, while programming, the size of memory to be
allocated in addition to the array size remaining constant. In programming there may be
scenarios where programmers may not know the memory needed until run time. In this case,
the programmer can opt to reserve as much memory as possible, assigning the maximum

memory space needed to tackle this situation. This would result in wastage of unused memory
spaces. Memory management operators are used to handle this situation in C++ programming
language.
11.

What are memory management operators?


There are two types of memory management operators in C++:

new
delete
12. What is array and its type?
13. What is the difference b/n array and pointer?

Pointer pointer is a variables that hold the address of another variable .It is used to manipulate
data using the address, pointer use the * operator to access the data pointed by them.
Array array use subscripted [] variable to access and manipulate the data ,array variables can be
equivalently written using pointer expression.
A special function Always called whenever an instance of the class is created.

Same name as class name


No return type
Automatically call when object of class is created
Used to initialize the members of class
class Test
{ int a,b;
Test()
{

a=9;b=8;

} };

Here Test() is the constructor of Class Test.

14. What is copy constructor?


Constructor which initializes it's object member variables ( by shallow copying) with
another object of the same class. If you don't implement one in your class then compiler
implements one for you.
for example:

Test t1(10); // calling Test constructor


Test t2(t1); // calling Test copy constructor

Test t2 = t1;// calling Test copy constructor


Copy constructors are called in following cases:
when a function returns an object of that class by value
when the object of that class is passed by value as an argument to a function
when you construct an object based on another object of the same class

15. What is default Constructor?

Constructor with no arguments or all the arguments has default values. In Above Question Test() is a
default constructor

16. What is friend function?


As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its
private and protected members. A friend function is not a member of the class. But it must be listed in
the class definition.

17. What is a scope resolution operator?


A scope resolution operator (::), can be used to define the member functions of a class outside the
class.

18. What do you mean by pure virtual functions?


A pure virtual member function is a member function that the base class forces derived classes to
provide. Normally these member functions have no implementation. Pure virtual functions are equated
to zero. class Shape
{ public: virtual void draw() = 0;}

19. What are the advantages of inheritance?


It permits code reusability. Reusability saves time in program development. It encourages the reuse of
proven and debugged high-quality software, thus reducing problem after a system becomes functional

20. What are virtual functions? Describe a circumstance in which virtual functions would be appropriate
Virtual functions are functions with the same function prototype that are defined throughout a class
hierarchy. At least the base class occurrence of the function is preceded by the keyword virtual. Virtual
functions are used to enable generic processing of an entire class hierarchy of objects through a base
class pointer. For example, in a shape hierarchy, all shapes can be drawn. If all shapes are derived from
a base class Shape which contains a virtual draw function, then generic processing of the hierarchy can
be performed by calling every shapes draw generically through a base class Shape pointer.

21. Distinguish between virtual functions and pure virtual functions


A virtual function must have a definition in the class in which it is declared. A pure virtual function does
not provide a definition. Classes derived directly from the abstract class must provide definitions for the
inherited pure virtual functions in order to avoid becoming an abstract base class

22.

What is the difference between parameter and arguments?

Parameter While defining method, variable passed in the method


are called parameters.
Arguments-While using those methods value passed to those
variables are called arguments.
Viva-Voice, It is not just the presentation of your project but also the representation
of your professional skills. We will provide you detailed study(in the form of
questioner asked by different professors) on various viva-voices conducted, which

will help you to face viva and score more in your final year project report.
A Person who is taking your viva-voice is completely depends on your explanation
about your project means he/she does not do any home work for taking your viva.
They start studying your project just before 10 minutes of your viva. If your report
has some problem related to index, content, coding don't worry about that you can
remove it just by showing confidence and doing professional talk in front of your
professor. We can classify the all viva questions into four category viz. ABOUT
PROJECT TITLE & PROJECT REPORT, DOCUMENTATION i.e.
THEORATICAL KNOWLEDGE, TESTING OF SOFTWARE AND ABOUT
PROGRAMMING.

1.

In the first category i.e. about project title the few questions are:

a) What is the significance of this title?


b) Why you choose this title?
c) Are you think that this title is suitable for Class XII ?
d) Can you give any other title to your project work?
e) Can you explain your title of the project in 100 words?
h) What does your project do?
i) How much time you taken in Analysis, Coding and Testing
k) What are the uses of the project?

You might also like