These are the C++ Basic Fundamental Questions asked in Interviews or Vivas.
1.
What is the difference between oop and pop?
A. Pop consists of writing a list of instructions for the
computer to follow and originating these instructions into groups known as
functions. Oops treats data as a critical element in the pgm development and does not allow it
to flow forcely around the system. It protects data from accidental
modification which is from outside functions.
2.
What is a class and object?
A.
The objects contains
the data and the code to manipulate that data. So, the entire set of data and code
of an object can be made a user defined datatype with the help of classes.
Objects are basic run timeentities in an object oriented
system.they may represent a person, a
place, a bank a/c or any data item that pgm has to handle.
3.
What is meant by encapsulation?
A.
The method of combining the data and functions into single
unit is called as data encapsulation.
4.
What is polymorphism?
A.
It is the ability to
take morethan oneform i.e., an operation may exhibit different behaviours in
different instances. there are two types. they are:
Static : the functions that are known at compilation
time.
Dynamic: the functions that are known at execution
time.
5.
What are different access specifiers and difference
between them?
A.
The members which has been declared as private are
accessible only with in class and the member functions of that class.
The members that have been declared as public can be
accessed outside of the class also.
The members which are declared as protected can be
accessed in the class or immediate derived class.
6.
What is meant by function overloading?
A.
Overloading means the use of the same thing or same function
for different purposes. C++ allows
overloading of different functions i.e., we can use the same function to
perform different tasks with same function name. this is also called as
function polymorphism.
7.
What is cout and cin?
A.
COUT: it is the o/p
statement is used to display the values of
variables on the screen or moniter.
CIN: it is a predefined object in c++ that represents
standard i/p stream.
8.
What is void pointer?
A.
To specify the return type of a function when it is not
returning any value.
To indicate an empty argument list to a function.
In c++ void is used as generic pointer.
9.
What is reference variable?
A.
C++ includes a new kind of variables known as reference
variable. A reference variables provides an alias name for a previously defined
variables.
Format: datatype &reference variable=variable;
10.
Define size-t?
A.
It is one of the variable like int or char. It is used in
new operator overloading concept.
11.
Difference
between reference & pointer variable?
A.
In reference we shall
access the duplicate af the variables by aliasing them.
In pointer we shall access the variables using their
addresses.
12.
What is the
difference between constant pointer and pointer to a constant?
A.
Constant pointer: const *p=10;
Pointer to a constant: const a=10;
&p=a;
13.
What is dazzling
pointer?
A.
The pointer that
points to a block of memory that does not exist is called a dazzling pointer or
wild pointer.
14.
What is the difference
between classes and structures in c++?
A.
Classes: in classes there is a security for variables.
Structures: in this there is no security for data
members and variables.
15.
What is the
importance of scope resolution operator?
A.
It is used for the purpose of accessing a total variable
name with in the function, when the global variable and local variable have the
same name. It is used to uncover a hidden variable.
16.
What is the
scope and life time?
A.
Scope: scope is
defined in which the variables defined.
Life time: it is defined as the ----- position in which
the variable is defined.
17.
What is the
importance of static data member?
A.
In some situations it is necessary to store the data members
for the all objects, so we use static data member.
18.
What are the main
characteristics of static member functions?
A.
A static function can have access to only static data
members declared in the same class.
Format:
Classname:: function name(arguments);
19.
What is a
friend function?
A.
The friend function can be declared by using the resolved
word friend. The functions that are declared with the keyword friend is known
as friend function.
20.
What is the
importance of friend function?
A.
It can be declared
either a public or private part of the class without effecting its meaning.
It can’t be called using the ojects of the class and it
can be invoked like a normal function.
21.
What is a friend class?
A.
We can also declare
all the member functions of one class as the friend functions of another class.
This class is friend class.
22.
What are the disadvantages of friend function?
A.
We can overload some operators.
It violates the datahiding concept by accessing private
data members.
23.
What is meant by Ambiguity?
A.
In Function overloading,some times functions are created
with one function name,same argument list and same return type.This time the
ambiguity occurs.
24.
Write the syntax for declaration of reference variable?
A.
Datatype &reference variable=variable;
25.
What is an Inline function?
A.
An inline function is a function that is expanded in a line
when it is invoked.
Syntax:
Inline datatype functionname(arguments list){ }
26.
What is the rule to initialize the default arguments?
A.
C++ allows us to call
a function without specifying all its arguments.In such cases,the function
assigns a default value to the parameter which does not have a matching
argument in the function call.Default values are specified when the function is
declared.
Ex:
Float amount(float principal,int period,float
rate=0.15);
The subsequent function call is
Value=amount(5000,7);
27.
What is the importance of constant arguments?
A.
Int strlen(const char *p);
The
qualifier const tells the compiler that the function should not modify the
argument.The compiler wouldn’t allow to modify the argument.This type of
declaration is significant only when we pass arguments by reference or
pointers.
28.
What is constructor and destructor? What is the
importance of constructor?
A.
A constructor is a special member function whose task is to
initialize the objects of its class.
Importance:It is special because its name is the same
as the class name.When an object is created ,the constructor is invoked.
It is called constructor because it constructs the
values of data members of the class.
A destructor
is used to destroy the objects that have been created by a constructor.Like a
constructor ,the destructor is a member function whose name is the same as the
class name but is preceded by a tilde(~).
Ex:~integer( ) { }
29.
Can we overload the destructor ?
A.
No,we can’t overload the destructor because it destroys the
object.
30.
Write the syntax to define the copy constructor?
A.
A copy constructor is used to declare and initialize an
object with the contents of another object.
Syntax:
Classname obj2=obj1;
Classname obj2(obj1);
31.
What is implicit constructor supplied by compiler?
A.
A constructor can also have default arguments which will be
specified at the last arguments position in the argument list.whenever an
object contains les number of arguments then the default arguments will be
substituted.
32.
What is the syntax for defining constructor and
destructor?
A.
Constructor:
Class
<classname>
{
Private:
Public:
<classname>
{
}
};
Destrutor:
~<classname>
{
}
33.
Write syntax for implicit and explicit calling of
constructors?
A.
Implicit call:
<classname>
<objectname>(list of values);
Explicit call:
<classname>
<objectname>=constructor(list of values);
34.
What is meant by operator overloading?
A.
The process of making an operator to exhibit different
behaviours at different instances is known as Operator Overloading.
35.
List the operators which can’t be overloaded?
A.
Operator Meaning
:: Scope resolution
operator
Sizeof( ) Size of operator
?: Conditional or
ternary operator
.* Pointer to member
access
36.
List the operators which can’t be overloaded using
friend functions?
A.
Operator
Meaning
= Assignment operator
( ) Function call
operator
[ ] Subscript operator
-> Class member access operator
37.
What are the rules to overload unary and binary
operators?
A.
Unary operators are overloaded bymeans of member functions
takes no arguments and no return values and the unary operator can be
overloaded by means of friend function which takes one reference argument.
Binary operator is overloaded through a member function
which takes only one argument but the binary argument is overloaded through a
friend function takes two explicit arguments.
38.
Write the syntax to overload unary and binary operator?
A.
Returntype operator operatorname( )
{
}
Friend returntype operator operatorname(classname
&address)
{
}
39.
What is an operator function?
A.
In case of conversion from user defined to basic type the
conversion function should be defined in
User defined class in the form of operator function.
40.
What is the syntax for operator function?
A.
Operator basicdatatype(
)
{
}
41.
How to differentiate post and preincrement operator
overloading?
A.
Prefix:
Returntype operator ++( );
Returntype classname::operator ++( )
{
}
Obj1=++obj2;
Postfix:
Returntype operator ++(int x);
Returntype classname::operator ++( int x)
{
}
Obj1=obj++;
42.
Can you declare a destructor as static?
A.
No,we can’t declare a destructor as static because suppose
when we declare a destructor as static the class will be destroyed.
43.
What is meant by Inheritance?
A.
The process by which objects of one class acquire the
properties of another class is called inheritance.
44.
How can you inherit private members?
A.
This can be accomplished by modifying the visibility limit
of the private member by making it as public.
45.
What are different visibility modes in Inheritance?
A.
There are three modes.
Private
Public
Protected
46.
How the constructors and destructors are moved in case
of multiple inheritance?
A.
In case of multiple inheritance the base classes are constructed
in the order in which they appear in the derived class.The base constructors
are called and executed before executing the statements in the body of the
derived constructor.
47.
Write the syntax to initialize base class constructor?
A.
Derived constructor
(a1,a2,a3):base1constructor(a1),base2constructor(a2)
{
}
48.
What is virtual base class?
A.
To eliminate duplicate copies C++ allows a technique called
virtual baseclass.Here only one copy of base class is copied.
49.
What is the difference between Function overloading and
function over riding?
A.
The mechanism of deriving a function in the derived class
for its own implementation which is already defined in the base class is called
overriding.
Overloading
Overriding
->The prototype of two functions are different ->The prototype of two functions are
same
->The names of the two functions are same ->The names of the two functions are
same
50.
How can you implement runtime polymorphism?
A.
It is implemented by using virtual functions.
51.
What is virtual function?
A.
The problem with the pointers to the derived class is that
we cant access the public members of the derived class using pointers to the
base class. We can access only those members which are inherited from the base
class and not the members that originally belongs to the derived class.for a
solution to the problem we have to use virtual functions.
52.
What is pure virtual function and write syntax for
this?
A.
A pure virtual function is a function that has no definition
with in the base class. When a base class member function is defined as empty
such a function is called do nothing functions.
Syntax:
Virtual
returntype functionname(Arguments )=0;
53.
What is abstract class?
A.
An abstract class is one that is not used to create
objects.An abstract class is designed only to act as a base class.the abstract
base classes are generally used in inheritance.
54.
What is the use of abstract class?
A.
The main purpose of the abstract class is to derive a class from
an already existing base class.
55.
What is Abstract datatype?
A.
Abstract collection of data elements and their accessing
functions where we are not concerned about how the accessing function will be
implemented is referred to as Abstract datatype.
56.
What is THIS pointer?
A.
This pointer is used to represent an object that invokes a
member function.
57.
What is a file?
A.
A file is a collection of related data stored in a
particular area on the disk.
58.
What is a Stream?
A.
The interface between the programmer and the I/O device
is known as stream.A stream is a sequence of bytes.
59.
What are predefined stream classes?
A.
There are two types:
Istream and ostream
60.
What are standard streams?
A.
Cin :
It
represents the input stream connected to standard input devices.
Cout:
It
represents the output stream connected to standard output devices.
61.
What are formatted I/O operations?
A.
C++ supports a number of features which were used for
formatting the output. They are
1.IOS class functions and flags
2.Manipulators.
3.User defined manipulators.
62.
What are predefined functions in Input and output
streams?
A.
Cin ,cout are the predefined functions in input and output
streams.These are obtained automatically when a program begins its execution.
63.
Write formatting flags defined in the IOS class?
A.
IOS::adjust field
IOS::float field
IOS::base field
64.
What is the significance of bit field?
A.
These are used to justify and scientific notation of
floating values.
65.
How to display trailing decimal points and zeros?
A.
Using IOS::show point ,here we can display trailing
decimal points and zeros.
Format:
Cout.setf(IOS::showpoint);
66.
What is a Manipulator?
A.
Manipulators are operators that are used to format the data
display.The most commonly used manipulators are endl and setw.
0 komentar:
Post a Comment