Fill in The Blanks:: Advanced C++ & Data Structures (Solved)
Fill in The Blanks:: Advanced C++ & Data Structures (Solved)
42. The push operation inserts an element at the end of a stack. (False)
43. It is not necessary for each node in a linked list to have a self-referential pointer. (False)
44. In physical memory, the nodes in a linked list may be scattered around. (True)
45. When the head pointer points to NULL, it signifies an empty list. (True)
46. Linked list are not superior to STL vectors. (False)
47. Deleting a node in a linked list is a simple matter of using the delete operator to free the
node’ s memory. (False)
48. A class that builds a linked list should destroy the list in the class destructor. (True)
49. Once an exception has been throwe, it is not possible for the program to jump back to the
throw point. (True)
50. In C++, only one catch block can handle all the exceptions. (True)
51. It is not possible to rethrow an exception. (False)
52. There can be only one catch block in a program.(False)
53. When an exception if throw, but not caught, the program ignorers the error. (False)
54. A class object passed to a function template must overload any operators used on the class
object by the template. (True)
55. In the function template definition it is not necessary to use each type parameter declared in
the template prefix. (False)
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
main = 100;
cout<<main++<<endl;
}
(a) 101 (b) 100 (c) None (d) Error: one cannot use main as identifier
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
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
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;
#include<iostream.h>
void main()
{
int i=5,j=0;
while(i-- || j++)
{
cout<<i<<" "<<j<<” ,” ;
}
}
(a) 5 1, 4 2, 3 3, 2 4, 1 5, (b) 4 0, 3 0, 2 0, 1 0, 0 0,
(c) 4 1, 3 2, 2 3, 1 4, 0 5, (d) None
void main()
{
int x=10;
(x<0)?(int a =100):(int a =1000);
cout<<a;
}
(a) Error (b) 1000 (c) 100 (d) None
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
cout<<arr[1][2]<<" "<<*(a+3);
}
(a) 55 33 (b) 33 55 (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
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.
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
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
(b) Non- Linear Data Structure
(c) Not a Data Structure
(d) Circular Data Structure
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
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
91.
#include<iostream.h>
class Base
{
int static i;
public:
Base(){}
};
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;
};
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
}
(a) zero one one two (b) zero one two
(c) zero two (d) none
int main()
{
myprofessor obj;
return 0;
}
#include<iostream.h>
class Base
{
public:
virtual void Method()=0{n=1;}
private:
int n;
};
class D1:Base {};
class D2:public D1
{
int i;
void Method(){i=2;}
};
int main()
{
D2 test;
return 0;
}