You are on page 1of 4

C++ Last Five Years Questions:

1. Short Notes on:

I. Copy constructor.
II. 2. Static data members and static methods.
III. 3. Virtual destructor.
IV. 4. Protected access specifier.
2. What is the advantage of passing parameters through call
by reference over call by value?
3. Explain the necessity of virtual base class in C++.
4. Explain function overloading.
5. What are the differences between new and malloc?
6. What is multiple inheritance? What is its syntax? Explain
the problem of multiple occurrence of the same base class in
the context of multiple inheritance.
7. Why << operator is always overloaded as a friend
function (and not as a member function) in a user defined
8. What is the prototype of a copy constructor for a class X?
When is the copy constructor called?
9. What is the prototype of a friend function for post
increment operator of a class X?
10. How is the runtime polymorphism achieved in C++?
11. How do you write an abstract class in C++?
12. Why is virtual destructor required?
13. What is this pointer?
14. When can a function call be used in the left side of an
assignment operator?
15. Explain, with examples, how to pass and return objects to
and from a function?
16. What is the meaning of polymorphism?
17. Suppose a class X in C++ is defined with three data
members: privateData, protectedData and publicData. These
data members are integers with access specification private,
public and protected respectively. Using this class explain the
scope where these data members can be accessed. What is the
default access specification of a member in a class in C++?
18. Suppose a class X is a friend of another class Y in C++.
What does that signify? Is class Y a friend of X? If a class Z is
a friend of Y then are X and Z are friends? Can you mention
one use of friend class or function?
19. Give an example code to define a reference to an integer
in C++. Is the following statement correct?
int &x=3000;
Suppose that x is a defined as a reference to y. Can I now
make x a reference to another variable z?
20. Suppose that class X has three constructors: X(), X(int),
X(int, int) . Also, suppose that class Y is derived from class X.
Class Y has a constructor Y (int, int, int). When an instance of
class Y is created, how many constructors will be called? How
does the programmer of class Y convey which constructor of
the base class will be called from the constructor of the Y
21. What is the syntax of a copy constructor? When is a copy
constructor invoked?
22. Give an example to show the meaning of private access
23. What are the different ways to initialize an array of
24. Show an example of defining reference to an integer. How
is a reference different from a pointer?
25. Why inline functions are better than macros? What is
multiple inheritance?
26. What is the advantages of new over malloc in C++?
27. What is a friend function? What is a friend class? If class
A is a friend of class B, is it true that class B is also a friend
class of A?
28. Compare and contrast between a reference variable and a
pointer variable?
29. Under what circumstances, the compiler chooses to
textually replace an inline function instead of making a
function call?
30. How do you define a reference to an integer variable?
How do you define a reference to an integer literal say 5?
31. Suppose that a class X has a static integer data member i.
How do you initialize this static member?
32. Suppose that a class X has a static integer data member i.
Also assume that a,b,c are instances of X. Further suppose
that a value of I is 0 at some point of time and then a.i, b.i, c.i
are incremented in that order. Now, what are the values of a.i,
b.i, c.i and X::i?
33. Distinguish between the following two statements.
X*a=new X(10);
X*a=new X[10];
34. Specify conditions when inline function in C++ not
textually replaced at its call.
35. When do we need to define friend functions instead of
member functions to implement operator overloading in C++?
36. Suppose a function f is a friend class to a class X. What is
the speciality of the function f? What is the syntax of
declaring f as a friend to class X? Can f be a public or private
member of X?