0% found this document useful (0 votes)
17 views6 pages

C++ VIVA Question and Answers

Uploaded by

Amulya Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
17 views6 pages

C++ VIVA Question and Answers

Uploaded by

Amulya Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

C++ VIVA Question and Answers

What is C++
C++ is created by BjarneStroustrup of AT&T Bell Labs as
anextension of C, C++ is an object-oriented computer language used
inthe development of enterprise and commercial applications.Microsoft’s
Visual C++ became the premier language of choiceamong developers
and programmers.

2.What are the basic concepts of object oriented programming?

It is necessary to understand some of the concepts used extensivelyin


object oriented programming.These includeObjectsClassesData
abstraction and encapsulationInheritancePolymorphismDynamic
BindingMessage passing

3.Define inheritance?

The mechanism of deriving a new class (derived) from an old class(base


class) is called inheritance. It allows the extension and reuseof existing
code without having to rewrite the code from scratch.Inheritance
is the process by which objects of one class acquireproperties of objects
of another class.

4.Define polymorphism?

Polymorphism means one name, multiple forms. It allows us to


havemore than one function with the same name in a program.It
allowsus to have overloading of operators so that an operation can
exhibitdifferent behaviours in different instances.

5.What is encapsulation?

The wrapping up of data and functions into a single unit (calledclass) is


known as encapsulation. Encapsulation containing andhiding
information about an object, such as internal data structuresand code.
What is message passing?
An object oriented program consists of a set of objects that
communicate witheach other. Message passing involves specifying the
name of the object, thename of the function and the information to be
sent.

7.What are tokens in C++?


The smallest individual units of a program is known as tokens. c++ has
the followingtokens :KeywordsIdentifiersConstantsStringsOperators

8.What is the use of enumerated data type?


An enumerated data type is another user defined type which provides a
way forattaching names to numbers thereby increasing
comprehensibility of the code. Theenum keyword automatically
enumerates a list of words by assigning them values0,1,2, and so on.

9.What is the use of default constructor?


A constructors that accepts no parameters is called the default
constructor.If nouser-defined constructor exists for a class A and one is
needed, the compilerimplicitly declares a default parameterless
constructor A::A(). This constructor is aninline public member of its class.
The compiler will implicitly define A::A() when thecompiler uses this
constructor to create an object of type A. The constructor willhave no
constructor initializer and a null body.

10.Define Constructors?

A constructor is a member function with the same name as its class. The
constructoris invoked whenever an object of its associated class is
created.It is calledconstructor because it constructs the values of data
members of the class.

How variabledeclaration in c++differs that in c?


C requires all the variables to be declared at the beginning ofa scope but
in c++ we can declare variables anywhere in thescope. This makes the
programmer easier to understandbecause the variables are declared in
the context of their use.

12.Define destuctors?
A destructor is called for a class object when that object passes out of
scope or isexplicitly deleted.A destructors as the name implies is used to
destroy the objectsthat have been created by a constructors.Like a
constructor , the destructor is amember function whose name is the
same as the class name but is precided by atilde.

13.What is a class?
A class is a collection of objects.

14.what is the difference between c &c++?


c++ia an object oriented programing but c is a procedure oriented
programing.c issuper set of c++. c can't suportinheritance,function
overloading, methodoverloading etc. but c++ can do this.In c-programe
the main function could notreturn a value but in the c++ the main function
shuld return a value.

15.What is copy constructor?


Copy constructor is a constructor function with the same name as the
class and usedto make deep copy of objects.

What isdefaultconstructor?

A default constructor is a constructor that either has no parameters, or if


ithas parameters, all the parameters have default values.

17.What is a scope resolution operator?


The scope resolution operator permits a program to reference an
identifier in theglobal scope that has been hidden by another identifier
with the same name in thelocal scope.

18.What is the difference between Object and Instance?


An instance of a user-defined type is called an object. We can instantiate
manyobjects from one class.An object is an instance of a class.
19.What is the difference between macro and iniine?
Inline follows strict parameter type checking, macros do not.Macros are
always expanded by preprocessor, whereas compiler may or may
notreplace the inline definitions.

20.How variable declaration in c++ differs that in c?


C requires all the variables to be declared at the beginning of a scope
but in c++ wecan declare variables anywhere in the scope. This makes
the programmer easier tounderstand because the variables are
declared in the context of their use.

What ismultipleinheritance?
A class can inherit properties from more than one class which is known
asmultiple inheritance.

22.what is the use of virtual destructor in c++?


A destructor is automatically called when the object is destroyed. A
virtualdestructor in C++ is used primarily to prevent resource leaks by
performing a clean-up of the object.

23.What do you mean by reference variable in c++?


A reference variable provides an alias to a previously defined variable.
Data -type & reference-name = variable name

24.What do you mean by implicit conversion?


Whenever data types are mixed in an expression then c++ performs the
conversionautomatically.Here smaller type is converted to wider
type.Example : in case of integer and float integer is converted into float
type.

25.What are virtual functions?


The virtual fuctions must be members of some class.They cannot be
static members.They are accessed by using object pointers.A virtual
function can be a friend of another class.

What isthedifferencebetweenclass andstructure?


By default, the members ot structures are public while that tor class
isprivate.structures doesn’t provide something like data hiding which is
provided by theclasses.structures contains only data while class bind
both data and memberfunctions.

27.What are storage qualifiers in C++ ?


Const
Keyword indicates that memory once initialized, should not be altered by
aprogram.
Volatile
keyword indicates that the value in the memory location can be altered
eventhough nothing in the program.
Mutable
keyword indicates that particular member of a structure or class can
bealtered even if a particular structure variable, class, or class member
function is constant.

28.What is virtual class and friend class?


Friend classes are used when two or more classes and virtual base
class aids inmultiple inheritance.Virtual class is used for run time
polymorphism when object is linked to procedurecall at run time.

29.what is an abstract base class?


An abstract class is a class that is designed to be specifically used as a
base class.An abstract class contains at least one pure virtual function.

30.What is dynamic binding?


Dynamic binding (also known as late binding) means that the code
associated with agiven procedure call is not known until the time of the
call at run time.It isassociated with polymorphism and inheritance.

Wha tis difference between function overloading and


operatoroverloading?
A function is overloaded when same name is given to different
function.While overloading a function, the return type of the functions
need to bethe same.
32.What are the advantages of inheritance?
Code reusabilitySaves time in program development.

33.What is a dynamic constructor?


The constructor can also be used to allocate memory while creating
objects.Allocation of memory to objects at the time of their construction is
known asdynamic construction of objects.The memory is allocated with
the help of the new

You might also like