C++ Interview Questions

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

C++ Interview Questions

C++ Interview Questions


1) Contrast and state the difference between visual c++ and ANSI c++?
Visual C++ deals with graphical user interface and is the most advanced IDE for creating
complex applications. This is used to create real time applications.
ANSI C++ is the updated and advanced version than the earlier versions of C++.
Libraries and functions are updated in ANSI C++ compared to the earlier versions.

2) State the difference between the structure for C and C++?


The main difference between the structure of C and C++ is, C struct can contain only data
and C++ has access limitations and contains functions such as public, private, etc.

3) Define about template in C++ and instantiation?


The C++ feature that supports the definition of an object of undetermined type is called a
template. Using a template allows the programmer to define the features of the class,
while reserving the option of binding the type of the class to the class itself until a class
of a particular type is actually needed. The creation of a class of a particular type is called
instantiation.

4) Define and explain about the classes in C++ comparing with C?


A C++ class builds on the concept of a structure. Whereas a C structure is a collection of
named fields, a C++ class is a collection of named fields and methods that apply to
objects of that class type. Additionally, the C++ language implements the concept of
information hiding, restricting access to certain members of the class to methods of the
class itself.

5) Explain about rational class?


Rational class contains two data members, numerator and denominator and seven method
members, reduce, add, multiply, divide, equal, print, and set rational. The methods in the
class Rational explicitly mention only one. This is because the class object for which they
are invoked is an implicit parameter for each routine.

6) Explain about Templates in C++?


C++ templates are used to optimize code. They are very powerful as they help the
program by providing various classes, functions and methods. There is also a
disadvantage when we are using C++ templates, they tend to duplicate themselves and
get installed which slows down the functioning of the program. This is avoided in Java.
7) Explain Encapsulation and differentiate with regards to C.
Encapsulation is an entirely new concept which is present in C++ but not in C. In
Encapsulation you can restrict the access of the functions to Public, private and Protected
which is not possible in C. It is a general practice among programmers to allow only
partial functions which can help in designing to be public while the rest of the code is
made into private or protected.
8) Explain multiple inheritances in C++?
Multiple inheritances in C++ are a controversial issue. In multiple inheritance a derived
class or an unrelated class can obtain function of the base class. In this process it can
obtain multiple inheritance. A derived class or unrelated class may obtain more than one
base class. This can benefit as well as destroy the structure of the program.
9) Explain about virtual member functions of C++?
Virtual member functions come into play when a function belonging to a derived class
over rides a base class. This is possible only when there are many similarities in the
number of parameters, function definition, object, etc. This increasingly becomes difficult
to process during the run time. At this point of time virtual member functions comes to
rescue. This overwhelming task is made easy by virtual functions tables.
10) Explain the basic steps to parse a C++ source code?
The main difficulty to parse a C++ code lies in the complex definitions of C++
identifiers. They should also satisfy complex scoping rules for C++. Also they should
define what type it is and to what type it belongs to. It should also satisfy the basic
criteria of parsing source code.

11) Explain about different problems which C++ faces today.


The main problem which C++ faces today is because of its large feature set. It is almost
similar to C language because of which much of the criticism faced by “C” is faced by
C++. It doesn’t have language features to create multi threaded software. Also this
language is unruly compared to modern languages such as Java which has both object
oriented and procedural programming.

12) Explain about name spaces?


Namespaces help you to group classes, functions, etc under one name which helps you to
access it at later stage. To access these name spaces we can use scope operator. During
name space naming there arises difficulty when a function uses the same name which
causes redefinition errors.

13) Explain about exceptions and its relation to handlers?


This function is used for exceptional circumstances and this is made possible by handlers.
This exception handler is placed in the code which throws exception and error. This
exception throws error when the condition is not satisfied. This handler is placed in a try
block in which throw function is present. After the try block a catch function is placed
through which exception handlers are declared.

14) Explain about static_cast?


Static cast is very helpful for conversions from pointers to related class and also from
derived class to base class. This static_cast is also helpful to convert base class to derived
class. Static_cast makes sure that atleast classes and objects are completed. This has its
disadvantages such as programmer should ensure that the object specified is being moved
to its destination.
15) Explain about reinterpret_cast?
Reinterpret_cast is platform specific. The code generated for reinterpret_cast is generated
for the platform which makes it not useful for inter operability. This transfers pointers,
irrespective of classes. This forms a image of the specific class and also pointer pointed
or the pointer itself is not checked. This can lead doors to security lapses.

16) Explain about explicit conversion within C++ and its supportability?
This explicit conversion is required where there is different interpretation on value. There
are two different types of explicit conversion such as c like casting and functional. This
explicit conversion can be applied indiscriminately on the code which significantly
increases errors during run time.

17) Explain about implicit conversion in relation to C++?


Implicit conversion does not require any operator for performing its function. It
automatically performs when a value is copied to the code. The only exception being, it
should be compatible. This allows conversions between bool to numerical types, pointer
conversions, and etc. significant runtime errors get reduced with this implicit conversion
because it accepts values which are compatible.

18) Explain about the class string stream?


This string stream class is defined by a standard header file . This class provides
flexibility in converting a string based object to stream. This is useful in extraction and
insertion of numerical, strings, characters, etc. This is useful to extract a specific
numerical from a string. This also aids in insertion.

19) What exactly a data structure performs in C++?


A data structure is a collection of data elements under one name. These data elements are
collectively known as members and they can have variable lengths and types.
Structure_name and object_name are two important types defined in C++. Structure types
are defined by structure_name and object_name contains valid identifiers.

20) I am getting an error at runtime for an oversized array but it never shows it as a fault
during debugging?
In C++ it is very correct syntactically to declare over sized array. It also never shows you
any error during compilation but it shows error during run time. The answer lies in
pointers. This problem can be mitigated if we can manually specify the memory location
by using a reference operator. Automatically pointers assign the variable to a certain
location and when it tries to extract during extraction it fails thus creating error.

You might also like