3 C++ and DS
3 C++ and DS
3 C++ and DS
Page 1 of 1
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
34. Static member functions can access only the _________ data members of a class. (Static)
35. The two types of polymorphism is : _____________ & ____________. (Run time and compile time.)
36. A file stream is an extension of a ______ stream. (console)
37. The Standard Template Library(STL) is a library of ________ templates.(container class)
38. Run time polymorphism is________ than the compile time polymorphism.
39. With private inheritance, public and protected members of the base class become _______ members of
the derived class. (private)
40. A tree node with no children is called a _______ node. (leaf)
41. The shape of a binary tree if determined by the order in which values are inserted. (True)
42. In inorder traversal, the node’s data is processed first, then the left and right nodes are visited. (True)
43. The STL stack container is an adapter for the ______, ________, and _________ STL containers.
(vectors, lists, deques)
44. A data structure that point to an object of the same type, as itself is known as a __________ data
structure. (self-refrential)
45. After creating a linked list’s head pointer, one should make sure it points to _______ before using it in
any operations.(NULL)
46. __________ a node means adding it to a list, but not necessarily to the end. (inserting)
47. In a ________ list, the last node has a pointer to the first node. (circular).
48. The ________ block contains code that directly or indirectly might cause an exception to be thrown.
(try)
49. When writing function or class template, one use a ______ to specify a generic data type. (type-
parameter)
50. A _______ template works with a specific data type. (specialized)
51. A _______ container uses keys to rapidly access elements. (associative)
52. __________ are pointer-like objects used to access information stored in a container.(Iterators)
53. In some cases the class must be declared(not defined ) before a reference is made to it. This is known
as ________. (forward declaration).
54. ________ are blue prints of a function that can be applied to different data types. (templates)
55. _______ and ______ are two error objects. (clog, cerr)
56. We can convert a class data type to basic data type using ________. (member conversion function)
Page 2 of 2
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
Page 3 of 3
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
56. It is possible to overload a function template and an ordinary (non-template) function. (True)
57. A class template may not be used as a base class. (False)
58. When declaring an iterator from the STL, the compiler automatically creates the right kind, depending
upon the container it is used with. (True)
59. ‘ios’ stream is derived from iostream. (False)
60. ‘eof()’ function returns zero value if the eofbit is set. (False)
(a) 123 (b) Compile time error (c) None (d) Run time Error
Page 4 of 4
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
Page 5 of 5
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
int a;
}
(a) 32 (b) 0 (c) Compile time error (d) Run time error
17. To execute a C++ program, one first need to translate the source code into object code. This process if
called_________.
(a) translating (b) sourcing (c) compiling (d) coding
Page 6 of 6
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
20. Each generic type in a template function definition is preceded by the keyword_____.
(a) class (b) type (c) function (d) template
}
(a) 14, 14 (b) 15, 14 (c) 14, 15 (d) 15,15
Page 7 of 7
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
{
int a[5] = {1,2,3};
for(int i=0;i<5;i++)
cout<<a[i]<<endl;
}
(a) No output (b) 1 2 3 garbage garbage
(c) 1 2 3 0 0 (d) There is a run time error
26. To delete a dynamically allocated array named ‘a’ , the correct statement is
(a) delete a; (b) delete a[0]; (c) delete []a; (d) delete [0]a;
Page 8 of 8
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
Page 9 of 9
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
x+=2;
cout<<x<<" ";
}
}
(a) 1 2 3 4 5 (b) 2 4 6 8 10 (c) Compile Time error (d) Runtime Error
36. What is the output of the following code if user enters “ This is a test” ?
#include<iostream.h>
#include<string.h>
void main()
{
char str[8];
cin>>str;
cout<<str;
}
(a) This is a test (b) This is a (c) This (d) Error
Page 10 of 10
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
cout<<x;
}
(a) 6 (b) 3 (c) Compile Time error (d) Runtime Error
}
(a) 10 (b) 3 (c) garbage value (d) Error
44. The design of classes in a way that hides the details of implementation from the user is known as:
(a) Encapsulation (b) Information Hiding
(c) Data abstraction (d) All of the above
Page 11 of 11
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
45. Which of the following keywords do you think can be used when declaring static members in a class?
(i) Public
(ii) Private
(iii) Protected
46. I want a nonmember function to have access to the private members of a class. The class must declare
that function:
(a) friend (b) inline
(c) static (d) virtual
47. The ability to reuse objects already defined, perhaps for a different purpose, with modification
appropriate to the new purpose, is referred to as
(a) Information hiding. (b) Inheritance.
(c) Redefinition. (d) Overloading.
48. What do you think is the outcome of calling a redefined non-virtual function using a base-class
pointer?
(a) The appropriate redefined version of the function will be used.
(b) The base-class version of the function will always be used.
(c) The outcome is unpredictable.
(d) A run-time error will occur.
49. A class member that is to be shared among all objects of a class is called
(a) A const member (b) A reference parameter
(c) A static member (d) A function member
Page 12 of 12
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
Page 13 of 13
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
66. If a tree has only one node than the tree may be a:
(a) Binary tree (b) Tertiary tree
(c) Not a tree (d) (a) & (b)
72. A Graph is a :
(a) Linear Data Structure
Page 14 of 14
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
74. The organization and management of data structures are take place in:
(a) Primary Memory
(b) Secondary Memory
(c) External Memory
(d) Primary & Secondary Memory
75. The node of the circular doubly linked list must have:
(a) One data and two address fields
(b) One data and one address fields
(c) Two data and two address fields
(d) Two data and one address fields
77. In an expression binary tree, to obtain the postfix form of the expression we traverse in:
(a) Pre order (b) Post order
(c) In order (d) Pre and Post order both
78. In a binary tree, to delete a node that has two children, we require:
(a) Post order successor
(b) Pre order successor
(c) In order ancestor
(d) In order successor
79. What is the max number of edges an undirected graph with N nodes can have?
(a) N (b) N^2
(c) 2N (d) none of the above
Page 15 of 15
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
81. One of the following algorithms is NOT an example of using the divide-and-conquer technique. Which
one?
(a) quicksort (b) mergesort
(c) bubblesort (d) binary search
82. To apply the binary search algorithm, the data items should be represented as:
(a) a binary tree (b) a list implemented as a linked-list
(c) a list implemented as an array (d) an ordered list implemented as an array
84. Suppose you have a directed graph representing all the flights that an airline flies. What algorithm
might be used to find the best sequence of connections from one city to another?
(a) Breadth first search.
(b) Depth first search.
(c) A cycle-finding algorithm.
(d) A shortest-path algorithm.
85. What kind of list is best to answer questions such as "What is the item at position n?"
(a) Lists implemented with an array.
(b) Doubly-linked lists.
(c) Singly-linked lists.
(d) Doubly-linked or singly-linked lists are equally best
86. The operation for adding an entry to a stack is traditionally called:
(a) add (b) append
(c) insert (d) push
87. A _______ performs the copying for value returns as well as for value parameters.
(a) Copy Constructor (b) Parameterize Constructor
(c) Default Constructor (d) none
89. Consider A and B as two operands, and “ +” as the operator, the presentation A + B is called:
(a) prefix (b) postfix
(c) infix (d) suffix
Page 16 of 16
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
91.
#include<iostream.h>
class Base
{
int static i;
public:
Base(){}
};
class Sub1: public virtual Base{};
class Sub2: public Base{};
class Multi: public Sub1, public Sub2 {};
void main()
{
Multi m;
}
In the above program, how many times Base’s constructor will be called?
(a) 1 (b) 2
(c) 3 (d) none
92.
#include<iostream.h>
namespace N1
{
int f(int n) {return n*2;}
}
namespace N2
{
int f(double n) {return n*3;}
}
void main()
{
using N1::f;
int i1=f(1.0);
using N2::f;
int i2=f(1.0);
}
In the above code what would be the values of i1 and i2
(a) i1=2 i2=2 (b) i1=2 i2=3
(c) i1=3 i2=2 (d) Error
93.
#include<iostream.h>
class Base
{
public : int a;
protected: int b;
private: int c;
Page 17 of 17
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
};
class Friend
{
Derived derived;
};
In the above code, which of the following variables can be accessed in "Friend"?
(a) only a and b (b) a,b and c
(c) only a (d) Error
Page 18 of 18
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
Page 19 of 19
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
}
(a) There is nothing wrong
(b) One cannot have a ‘Base’ pointer to ‘Derived’ since it is not derived publicly
(c) One need a derived class pointer to point to a derived class.
(d) One required to code a constructor for Derived.
int main()
{
myprofessor obj;
return 0;
}
(a) professor researcher teacher myprofessor
(b) researcher professor teacher myprofessor
(c) myprofessor teacher researcher professor
(d) myprofessor researcher professor teacher
Page 20 of 20
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
private:
int n;
};
class D1:Base {};
class D2:public D1
{
int i;
void Method(){i=2;}
};
int main()
{
D2 test;
return 0;
}
(a) There is no error.
(b) There is a syntax error in the declaration of “ Method” .
(c) Class D2 does not have access to “ Method” .
(d) Class D1 must define “ Method” .
Page 21 of 21
ACTS National Resource Center, Pune
Question Bank – Advanced C++ & Data Structures (Solved)
Page 22 of 22