Total Pageviews

Friday, August 15, 2008

Basics on C++

C++:
1. Who has developed C++ and when it has been developed?
C++ was developed by Bjarne Stroustrup in the early 1980’s.
2. What are the languages from which C++ has been evolved?
C & Simula67.
3. What was C++ initially called?
C++ was initially called as “C with classes.
4. What kind of approach is used by C++ top-down or bottom up?
Bottom-up.
5. What are the applications of C++?
C++ has many applications in the real world. It is used to develop compilers, editors, databases, object oriented libraries etc.
6. What is the single line comment used in C++?
Double slash (//) is the single line comment used in C++.
7. What is the multi line comment used in C++.
/*…*/
8. How do you use comments in C++.
Both /*…*/ and // are the comments used in C++. One is multi line comment and the other is single line comment.
9. Can you nest comments in C++.
No.
10. What comments are used for?
a. Documentation of variables and their usage
b. In explaining difficult sections of code.
c. Describes the program, author, date, modification changes, revisions etc.
d. Copyrighting.
11. What is statement terminator in C++?
Semicolon (;)
12. Is C++ language case sensitive or not?
C++ language is case sensitive and the programs are written in lower case.
13. What do you mean by predefined?
The function that has already been written, compiled, and linked together with a program at the time of linking is called predefined.
14. What does the keyword “void” indicate?
Void indicates that the function does not return any value.
15. What is namespace?
Namespace provides a scope for the identifiers used in the C++ program.
16. What is the default return type of main () in C++?
In C++ int is the default return type of main ().
17. What do you mean by trigraph sequences?
Trigraph sequences help us to enter certain characters that are not available on some keyboards.
Ex.:??/ --- represents ^ (caret)
18. What are tokens in C++?
Smallest individual units are called tokens.
19. What are the types of tokens in C++?
Keywords, identifiers, constants, strings, special symbols, operators.
20. What do you mean keyword?
Keyword has a fixed meaning that cannot be changed.
21. How many keywords are there in C++ and ANSI C++.
In C++ there are 48 keywords plus 15 keywords in ANSI C++.
22. What is single character constant?
A single character enclosed within a pair of single quotes is called single character constant.
23. What is string constant?
Sequence of characters enclosed in double quotes.
24. What are escape sequences?
The combination of backslash (\) and some character together which together represent one character are called escape sequences.
25. What do you mean by initialization of variable?
Initialization is the process of assigning a value to variable at the time of declaration.
26. What are constants?
The values which do change during program execution are called constants.
27. What are identifiers?
The names of arrays, classes, functions etc created by the user are called identifiers.
28. What are the rules to be followed while naming an identifier?
The following rules are to be followed while naming an identifier:
a. Identifier should not be started with a digit.
b. Alphabetic characters, underscores and digits are to be used.
c. Identifiers are case sensitive.
d. Keywords cannot be used as identifiers.
29. What are the user defined data types in C++?
Class, enum, structure and union are the user defined data types in C++.
30. Name the built in data types in C++.
Integer, float, double, character and void.
31. Name the derived data types in C++.
Functions, pointers, arrays and reference are the derived data types.
32. What is other name for built in data types?
Basic or fundamental data types.
33. What is the range of integer?
-32768 to 32767
34. What is the range of float?
3.4E-38 to 3.4e+38
35. What is the range of char?
-128 to 127
36. What is the range of double?
1.7E-308 to 1.7E+308
37. What is the range of long double?
3.4E-4932 to 1.1E+4932
38. What is the number of bytes occupied by integer?
2 Bytes.
39. What is the number of bytes occupied by float?
4 Bytes.
40. What is the number of bytes occupied by double?
8 Bytes.
41. What is the number of bytes occupied by character?
One byte.
42. What is the number of bytes occupied by long double?
10 bytes.
43. What is the use of void?
Void is used to mention the return type of a function, to specify empty parameter list in a function and to declare generic pointers.
44. What is the use of generic pointer?
A pointer which can be assigned to any pointer value of any basic data type is called generic pointer.
45. Give the syntax of enum with an example?
enum identifier {value1, value2, value3};
Ex.: enum weekday {Sunday, Monday, Tuesday};
46. What is the difference between enum definition in C and C++?
In C an enum defined within a structure is globally visible, but in C++ an enum defined within a class or structure is local to it.
47. What do you mean by variable and “value” of a variable?
Variable is a data name used to store a data value and is volatile. “Value” is the data stored in or assigned to a variable.
48. What is the other name for symbolic names?
Symbolic names are also called as constant identifiers.
49. What is the use of keyword const?
Const is a keyword using which when a variable is declared, the value of it cannot be changed during the program execution.
50. What is the use of keyword volatile?
Volatile keyword is used to inform the compiler that the variable can be modified by the external sources.
51. What is the operator for exponentiation in C++?
C++ doesn’t have any operator for exponentiation.

52. What do you mean by integer expression?
The arithmetic expression in which all the operands are integers is called integer expression.

53. Which operator cannot be used with real operands?
Modulus operator (%).
54. Give an example for shorthand assignment operation?
a=a*3 can be written as a*=3;

55. What are the unary operators?
Increment (++) and decrement (++) are the unary operators.

56. Explain is the difference between prefix and postfix increment operator?
Prefix operator first increments the value and then assigns the value to the variable whereas postfix operator first assigns the value and then increments it.
57. What is the use of bitwise operators?
Manipulation of data at bit level is done using bitwise operators.

58. What are the ternary operators?
The pair “? :” are the ternary operators.

59. Give an example of comma operator and how is it evaluated?
Ex.: c= (a=3, b=2, a*b);
It is evaluated from left to right.

60. What is the use of “sizeof” operator?
Sizeof operator returns the number of bytes a variable occupies.

61. What is implicit type conversion?
The automatic conversion of ‘lower’ data type to ‘higher’ data type to maintain the significance of data is called implicit type conversion.

62. What do you mean by operator precedence?
Operator precedence is used to determine the order in which different operators in an expression are evaluated.
63. What do you mean by associativity of an operator?
The evaluation of operators from ‘left to right’ or ‘right to left’ which are of the same precedence based on their levels is called associativity.

64. Which operator has the lowest precedence?
Comma operator (,).

65. What is the difference between the operators ‘=’ and ‘==”?
Equal to ‘=’ is an assignment operator i.e., the value on the right side of ‘=’ is stored in the variable on right side. Whereas ‘==’ is comparison operator i.e., it is used to compare 2 values whether they are equal or not.
66. What is the identifier used in C++ similar to printf () in C?
Cout is the identifier used in C++ similar to printf () in C.
67. What is the name of the operator “<<”?
“<<” operator is called as insertion or put to operator.
68. What is the name of the operator “>>”?
“>>” operator is called extraction or get from operator.
69. What is the identifier used in C++ similar to scanf () in C?
Cin is the identifier used in C++ similar to scanf () in C.
70. In which header file are cout and Cin found?
In the header file .
71. Can you read multiple words using “cin”?
No, multiple words cannot be read using cin.
72. What do you mean by cascading of operators? Give an example.
The multiple use of insertion or extraction operator in a statement is called cascading of operators.
Ex.: Cin>>marks1>>marks2>>marks3;
73. What are the sections of a C++ program?
There are basically 4 sections in a c++ program:
Include files section
Class declaration section
Member functions section
Main.
74. Name the text editors in which a C++ program can be created.
UNIX – vi or ed
DOS – edlin or any other
Word processor under non document mode.
75. What are the file extensions which can be used for C++ program?
File extensions that can be used for C++ are: .c, .C, .cc, .cpp, .cxx.
76. Which system use the .cxx file extension?
Zortech C++
77. Which file extension does UNIX AT & T version use?
.C and .cc
78. What does the header file consist of?
header file is used by many standard library header files which use classes and functions.
79. What is the difference between C & C++ based on name limit?
C recognizes only first 32 characters in a name whereas C++ has no restrictions on the name limit.
80. List new keywords added to C++.
Class, delete, private, protected, public, friend, inline, new, operator, this, throw, try, template, catch, asm, virtual are the new keywords added to C++.
81. What is the difference between the array declarations in C & C++? Give an example.
The declaration of arrays in C & C++ varies only in case of strings.
Ex.: char string[5] = “array”; valid in C
char string [6] = “array”; valid in C++
In C, the size of string array is equal to the size of string, but in C++ the array size should be one larger than the original string size.
82. What is the number of bytes occupied by “sizeof (‘a’)”?
It occupies one byte. Unlike in C, ‘a’ is not stored as int it is considered as char value.
83. What is the advantage of C++ in case of variable declaration?
In C++ variables can be declared anywhere in the program just before its use or in the starting of the program.
84. What is the use of storage classes?
Storage classes are used to provide the details of location and the visibility of the variables.
85. What are the types of storage classes.
The different types of storage classes in C++ are automatic, register, static and extern.
86. What is the difference between static and global variable?
Static variable declared anywhere in a file is accessed by all the functions of the same file whereas global variable can be accessed by all the functions from the same and other files.
87. What is the other name for global variable?
External variable.
88. What are the values stored in storage classes when they are declared?
Static and extern are automatically initialized to zero when they are declared, while the others contain garbage values unless they are initialized.
89. Define #include.
#inlcude is a preprocessor directive that helps the named file to be inserted in place of #include.
90. What is the use of #define.
#define is a preprocessor directive which defines a substitute text for a given name.
91. What is dynamic initialization?
Initialization of variables at run time is called dynamic initialization.
92. What is a reference variable and what is its use?
Reference variable is used to provide an alias name for an already defined variable and should be initialized at the time of declaration. It is mainly useful when passing arguments to functions.
93. Write the syntax of using reference variable.
Syntax: int cost;
int & price = cost;
Here, cost is the already defined variable and price is the reference variable.
Change in any of the variable will affect the other variable.
94. What is a qualifier?
A qualifier is used to change the meaning of declaration of data.
95. What are the categories of relational operators?
Equality and ordering are the categories of relational operators.
96. Name the equality and relational operators.
Equality operators: ‘==’ and ‘!=’
Relational operators: <, >, <=, >=
97. List few new operators used in C++.
>> - Extraction operator
<< - Insertion operator
:: - Scope resolution operator
.* - Pointer to member operator
->* - Pointer to member operator
::* - Pointer to member declarator
new - Memory allocation operator
delete - Memory removal operator
98. What is the use of scope resolution operator?
Scope resolution operator is used to access the global variable when present inside a block where a local variable is other wise accessed using the normal mode.
Syntax: :: .
99. What are the memory management operators used in C++?
New and delete are the memory management operators used in C++.
100. What is the use of new operator?
New operator is used for dynamic allocation of memory and can be used instead of malloc ().
101. What is memory leak?
Memory leak is the situation which arises when dynamically allocated memory is not handled properly leading to memory loss, or non traceable memory.
102. Define volatile.
Volatile keyword is used to indicate that the data variable declared as volatile is not under the direct control of the compiler.
103. What are the manipulators?
Manipulators are the operators used to format the display of data. Endl and setw are the manipulators in C++.
104. What is the linefeed operator used in C++?
Endl is the linefeed operator used in C++.
105. Give an example for explicit type conversion of variables used in C++.
Ex.: price = total/ float (no)
106. What is integral widening conversion?
The conversion of char or short int to int when used in an expression is called integral widening conversion.
107. What is implicit conversion?
The automatic conversion of lower data type to higher data type when mixed in an expression is called implicit conversion.
108. What is the difference between “constant pointer” and “pointer to a constant”?
The difference is that when we use constant pointer we cannot change the address the pointer is initialized to whereas in case of pointer to a constant, data that it points to cannot be changed.
109. What is the use of const_cast operator?
Const_cast operator is used to explicitly override const or volatile in a cast.
110. Write the syntax for const_cast operator.
const_cast (object);
111. What is the use of reinterpret operator?
Reinterpret operator is used to change one type into a fundamentally different type.
112. What is the use of dynamic_cast operator?
The operator used to cast the type of an object at runtime is called dynamic cast operator.
113. What is RTTI?
RTTI is run time type identification which uses the operator dynamic_cast.
114. What is the use of typeid operator?
The operator used to retrieve the types of unknown objects is called typeid operator.
115. Write the syntax for typeid operator.
Syntax:
char * = typeid (object).name ();
116. What is anonymous union?
Anonymous union is unnamed union and the members of which can be used a normal variables.
117. List the decision-making statements.
If, Switch, Conditional operator statement and Goto are decision-making statements.

118. What is the use of decision-making statements?
Decision-making statements are to used to control the flow of execution of statements.
119. List the control structures in C++.
Sequence, selection and loops are the control structures in C++.
120. List the different forms of If statement.
The different forms of if statement are simple If statement and If..Else statement.
121. Write the syntax for simple If.
Syntax:
if (condition)
{
statements;
}
statements;
122. Write the syntax for if..else.
Syntax:
if (condition)
{
statements;
}
else
{
statements;
}
statements;
123. What is the multiway decision statement in C++.
The multiway decision statement in C++ is switch.
124. Write the syntax for switch statement.
Syntax:
switch (expression)
{
case 1: statements;
break;
case 2: statements;
break;
………………
………………
default: statements:
break;
}

125. Where should be the label default placed in switch statement?
It can be placed anywhere in the switch statement, in the beginning, middle, or at the end. If all the matches fail, the statement sequences of the default get executed.
126. What is ternary operator? What is its use?
“?:” is called ternary operator or conditional operator. It can be used instead of If statement.
127. What are the types of loops in C++?
Do...While, while and for are the types of loops in C++.
128. What is test expression?
Test expression is the expression used to determine the course of action for conditional or iterative constructs.
129. Name the entry controlled loop/s.
While and for are entry controlled loops.
130. Name the exit controlled loop/s.
Do…While is the exit controlled loop.
131. What is the other name for entry controlled and exit controlled loops?
Entry controlled loop is also called pre-test loop and exit controlled loop is called post-test loop.
132. What are the steps in looping procedure?
Initialization, execution of steps in loop, test condition and updating control variable.
133. Name the types of loops based on the type of counter variable and its value.
Based on the type of counter variable and its value loops are divided into types.
a. Counter controlled loops -- value of counter variable is known prior to loop execution
b. Sentinel controlled loops -- value of counter variable is not known prior to loop execution.
134. Write the syntax for do…while.
Syntax:
do
{
statements;
} while (condition);
135. Write the syntax for while statement.
Syntax:
while (condition)
{
statements;
}
136. Write the syntax of for statement.
Syntax:
for (initialization; condition; updating control variable)
{
statements;
}
137. What is the use of break statement?
Break statement is used to exit the control from control structures.
138. What is the use of continue statement?
Continue is used to skip the statements till the end of loop in which it is used.
139. What is a control statement?
A control statement is the one that decides the next statement to be executed based on a test condition.
140. What is control variable?
A control variable is the one that is systematically changed during the loop execution and terminates the loop when the test condition no longer satisfies.
141. What is the difference between while and do…while?
The difference between while and do…while is that while loop gets executed only when the condition is true, whereas do…while gets executed atleast once irrespective of the condition.
142. Why is do…while called exit controlled loop?
The test condition is evaluated at the end of the loop which controls the loop execution, so do…while is called exit controlled loop.
143. Why are while and for called entry controlled loops?
In the while and for loops the condition is checked at the beginning based on which the body of the loop is executed. So, they are called entry controlled loops.
144. By which operator are the multiple arguments in the increment section of for loop are separated?
comma (,).
145. How can you setup time delay for loops?
We can setup time delay for loops by placing null statement at the end of for loop.
Ex.: for (i=1;i<=500;i++)
;
146. How many loops can a break exit at a time?
One loop.
147. What is the difference between break and goto?
Break statement is used to transfer the control out of the loop to the next statement following the loop whereas Goto is used to transfer the control to anyplace in the program.
148. What is for loop called without the test condition?
Infinite loop.
149. What is the other name for sentinel controlled loop?
Indefinite repetition loop.
150. What is the other name for counter controlled loop?
Definite repetition loop.
151. What is conditional operator? What is its use?
?: is called conditional operator and is used instead of If statement.
152. What is an array?
An array is collection of similar kind of data types in continuous memory locations and is fixed in size.
153. What are the individual values of arrays called?
Indices or elements.
154. What are the things to be specified when declaring an array?
Name of the array, type and size are to be specified when declaring an array.
155. How do you initialize a 2-D array?
Two-dimensional array can be initialized in the following way:
Ex.: int arr[2][3] = {1,2,3,4,5,6};

int arr[2][3] = {{1,2,3}, {4,5,6}}

int arr[2][3] = {
{1,2,3},
{4, 5,6}
};
156. In a multidimensional (2-D or 3-D) array which dimension can be optional?
First dimension.
157. What are dynamic arrays?
Arrays created at run time are called dynamic arrays.
158. In which class are the strings manipulating functions present?
In the class.
159. List few operations that can be performed on strings.
String comparison, reading string from keyboard, assigning strings, finding substring, finding length of string, string swap, sorting of strings, modifying string, accessing individual characters of a string are few of the operations that can be performed on strings.
160. List the string constructors.
The following are the string constructors:
String () – to create an empty string
String (const chat *strg) – to create a string object from null terminated string
String (const string &strg) – to create a string object from another string object.
161. Name some functions of string class.
Find (), insert (), length (), replace (), resize (), swap (), compare (), append () etc are some functions of string class.
162. List the operators used for string objects.
All the relational operators (>, >=, <, <=, !=), =, +, +=, >>, <<, [], == are the operators used for string objects.
163. What are the functions used for accessing individual characters of a string and substrings?
Find (), find_first_of (), find_last_of (), at (), substr ().
164. Define structure.
Structure is a collection of different data types.
165. Write the syntax for structure.
struct
{
data type variable1;
data type variable2;
………..
};
struct struct1, struct2;
166. Write the different ways of structure declaration with examples.
There are 2 ways of declaring a structure.
Ex1: struct student
{
int roll_no;
char name[15];
};
struct student stud1, stud2;
Ex2: struct
{
int roll_no;
char name[15];
} stud1, stud2; //Tag name is optional
167. How do you initialize structure variables?
The structure variables cannot be initialized in the template. There are 2 ways of initializing a
structure.
1. main()
{
struct score
{
int mat1;
int mat2;
};
struct score m1 = {90, 88};
…….
}
2. struct score
{
int mat1;
int mat2;
} m1 = { 99, 70};
main ()
{
struct score m2 = { 86. 97};
……………
}
168. Can the structure variables be initialized at declaration?
No, the structure variables cannot be initialized at declaration.
169. How do you access structure members?
Structure variables are accessed using the member operator (.).
syntax: .datavariable
Ex: m1.sub;
170. What is the other name for member operator (.)?
The other name for member operator is Dot operator or period operator.
171. Can you compare structures like string comparison?
No, we cannot compare structures directly. If we want to compare we have to write our own functions.
172. Can you perform logical operations on structure variables?
No, logical operations cannot be performed on structure variables directly. If we want to compare we have to compare the structure members individually.
173. Explain the reason why you can’t compare structures?
The slack bytes which are stored in the structure variables are undefined and are machine dependent. So, even though the value of 2 data members may be same but because of slack bytes they may not be equal. That is the reason we can’t compare structures.
174. What is slack byte in terms of structure?
Normally when structures are stored there is an unoccupied byte between two variables, this
unoccupied byte which is called slack byte.
175. Write the syntax for Union declaration.
union
{
data_type var1;
data_type var2;
}var;
176. What is the difference between structure and union?
Structure has separate memory allocation for each and every member of it whereas union
has a common memory allocation for all the members together and allocates memory
enough to hold the largest variable type.
177. What is the difference between main () in C and C++?
Main () in C does not mention any return type whereas in C++ main () should return a value and the default return type is int.
178. What is a function?
A function is a self contained block of code that does a certain action.
179. What does the function definition should include?
Function definition should include function name, return type, argument list, local variable declarations, function statements and a return statement.
180. Is it mandatory to use function prototyping in C++?
Yes, it is mandatory to use function prototyping in C++ unlike in C where it is optional.
181. What does function declaration or function prototype include?
Return type, function name, arguments list, terminating semicolon.
182. Write the syntax for function prototype.
Syntax: return type (arguments);
183. What is the use of function prototyping?
Function prototyping provides the information of function such as type and number of arguments to the compiler, so that it ensures proper execution.
184. Write the syntax for function definition.
(parameters)
{
variable declaration;
statements;
return statement;
}
185. What is the default return type for a function?
Integer.
186. What is the difference between formal parameters and actual parameters?
The parameters used in function definition and prototype are formal parameters and the ones
used in function calls are call actual parameters.
187. Which of the following function declaration is correct?
int total (int a, int b, int c)
int total (int, int, int)
Both of the function declarations are correct, because in C++ the names of the arguments in function declaration are optional.
188. Is it legal to use function call on left hand side of an assignment operator?
Yes, it is legal to use function call on left hand side of an assignment operator but only when return by reference is used.
189. How do you declare an open parameter list in function?
Open parameter list can be declared by using the following syntax:
void (…);
190. What is parameter passing?
The method of passing data from one function to another is called parameter passing.
191. What is recursion?
Recursion is the process where a function calls itself repeatedly.
192. Which data structure logic is used for recursion?
Stack.
193. What does extern mean in a function declaration?
Extern indicates that the function’s definition is in another source file. But there is no formal difference between extern int a (); and int a ();
194. What is the use of return by reference? Give an example for return by reference.
When we use return by reference in the functions, the function returns a reference to the arguments and not the values, using which the tracking of the arguments is made easy.
Ex.: int & equal (int &a, int &b)
{
if (a == b)
return 1;
else
return 0;
}
195. Which storage class is used to retain the value of variable between function calls?
Static storage class.
196. What is the disadvantage of macros?
When we use macros the error checking is not done during compilation unlike for functions where error checking is done.
197. What is preprocessor?
Preprocessor is a program that performs preliminary processing for expanding macro code templates to produce the corresponding code.
198. What are the important steps of preprocessor?
The following are the important steps of preprocessor:
a. replace each #include directive with the corresponding file contents
b. to process macro definitions and macro calls.
c. replace each escape sequence with the corresponding character.
199. What are inline functions?
An inline function is the one when invoked the compiler replaces the function call with the function code.
200. Write the syntax for inline function.
Syntax: inline
{
body;
}
201. What is the use of default arguments?
Default arguments are used when a same value is repeatedly used in the function. In such cases, the function arguments need not be specified and the compiler takes the default value specified.
202. Give an example for default arguments.
Ex.: float area (float r, float pi = 3.14);
a = area(10, 3.143); //both arguments specified
a = area (10) // only one argument is specified
203. What is the order in which default arguments are to be specified?
Default arguments are to be specified from right to left.
204. In terms of function overloading what are the steps involved in invoking a function?
The following steps are involved in invoking a function in terms of function overloading:
a. An exact match is searched first.
b. If not found, an integral conversion of data types is done.
c. Next implicit conversions are tried.
d. User defined conversions are tried.
205. What does the declaration of an argument in the function as const mean?
If an argument in function is declared as const then the function cannot modify the value of it.
206. When are the inline functions failed?
Inline functions may fail when functions contain static variables, when they are recursive, if switch, goto exists etc.
207. What is the disadvantage of using inline function?
Inline function causes the program to occupy more memory because whenever an inline function is called the compiler replaces the function call with the function body.
208. What are pointer variables?
Variables that hold memory addresses are called pointer variables.
209. What are pointer constants?
Pointer constants are the memory addresses in a computer which cannot be changed.
210. Write the syntax for pointer declaration.
syntax: data_type *ptr;
211. Give an example for initializing pointer variable.
Ex.: int x, *ptr;
ptr = &x;
Now ptr contains the address of the variable x.
212. How do you declare and initialize a pointer to pointer?
EX: int sum, *ptr1, **ptr2;
sum = 3;
ptr1 = & sum;
ptr2 = & ptr1;
213. Can a pointer variable be multiplied by a constant?
No, a pointer variable cannot be multiplied by a constant.
214. How do you initialize pointer variable with an array?
When initializing a pointer variable with an array only the base element of the array is assigned to pointer variable.
Ex: int a[3], *ptr;
ptr = & a; or
ptr = & a[0];
Because the all the array elements are stored in continuous memory locations, assigning of first value of array is sufficient to access all the array elements.


Object Oriented Programming:
1. List few features of object oriented programming.
Object oriented programming features:
Follows bottom up approach.
Emphasis is on data.
Programs are divided into objects.
Functions and data are bound together.
Communication is done through objects.
Data is hidden.
2. List features of procedure oriented programming.
Procedure oriented programming features:
Follows top down approach.
Emphasis is on procedure.
Programs are divided into functions.
Data moves around freely.
3. What are the basic concepts of OOPs?
The following are the basic concepts of OOPs:
Classes, Objects, Data abstraction and encapsulation, Polymorphism, Inheritance, Message Passing, and Dynamic Binding.
4. What is a class?
Class is an entity which consists of member data and member functions which operate on the member data bound together.
5. What is an object?
Objects are instances of classes. Class is a collection of similar kind of objects. When a class is created it doesn’t occupy any memory, but when instances of class is created i.e., when objects are created they occupy memory space.
6. What is data encapsulation?
Wrapping up of member data and member functions together in a class is called data encapsulation.
7. What is data abstraction?
Data abstraction refers to the act of providing only required features and hiding all the non-essential details for usage.
8. What are ADTs?
ADTs stand for abstract data types. Classes which provide data abstraction are referred to as ADTs.
9. What is inheritance?
The process of inheriting the properties of one object by another object is called inheritance.
10. What is polymorphism?
The feature of exhibiting many forms is called polymorphism.
11. What are the steps involved in message passing?
The following are the steps involved in message passing:
Creating classes, creating objects, and creating communication between objects.
12. What is dynamic binding?
The feature that the associated code of a given function is not known till run time is called dynamic binding.
13. What are the advantages of OOP?
Data hiding helps create secure programs.
Redundant code can be avoided by using inheritance.
Multiple instances of objects can be created.
Work can be divided easily based on objects.
Inheritance helps to save time and cost.
Easy upgrading of systems is possible using object oriented systems.
14. Give an example for object based programming language.
Ada is an example for object based programming language.
15. Write the features of object based programming language.
Data hiding, data encapsulation, operator overloading and automatic initialization and clear up of objects are the important features exhibited by object based programming languages.
16. Give some examples of pure object oriented languages.
Eiffel, Java, Simula, Smalltalk are some pure object oriented languages.
17. List the areas of applications of object oriented programming?
The following are few areas of applications of object oriented programming:
CAD/CAM systems
Office automation and decision support systems
Object oriented databases
Real time systems
Simulation and modelling.
18. What is the difference between structure in C and class in C++?
In C structure, by default the members are public. Whereas in C++ class, by default the members are private.
19. What are the sections in class specification?
There are basically two sections in class specification: Class declaration and class function definition.
20. Write the syntax for class declaration.
Syntax:
class
{
private:
variables;
functions;
public:
variables;
functions;
};
21. What are class members?
The variables and functions used in a class are called class members.
22. What are the visibility labels?
Private, public and protected are the visibility labels.
23. Give an example for class declaration.
Ex.:
class area
{
int r;
public:
void get(int r);
void area(int r);
};
24. How does a class provide data hiding?
Data hiding is provided by a class by the use of visibility label private which allows only the member functions to access the data declared as private.
25. What are the ways of defining member functions?
Member functions can be defined in two ways, one inside the class definition and the other outside the class definition.
26. Write the syntax for defining member functions inside the class.
Syntax:
class
{
private:
variables;
public:
variables:
return type
{
statements;
}
};
27. Write the syntax for defining member functions outside the class.
Syntax:
return type :: (arguments)
{
body;
}
28. What does member functions represent?
Member functions of a class represent the behaviour of a class.
29. Write the syntax for making an outside function inline?
Member functions can be made inline even though we define them outside the class by using the keyword inline.
Syntax:
class
{
variables;
public:
return type (arguments);
};
inline return type :: (arguments)
{
body;
}
30. What is an object?
A region of storage with associated semantics is called an object.
31. What is instantiation?
The process of creating objects from a class is called instantiation.
32. Define attribute.
Attribute is the property of an object and cannot exist independently.
33. What is null object?
Null object is an object of a class which is used to indicate that a real object of that class does not exist.
34. What is class invariant?
A class invariant is a condition that defines all valid states of an object. It ensures the proper working of class.
35. What is stack unwinding?
Stack unwinding is the process during exception handling when destructor is called for all local objects between the place where the exception was thrown and caught.
36. What are proxy objects?
Proxy objects are the objects that stand for other objects.
37. What is the other name for proxy objects?
Surrogates.
38. Write the syntax for accessing member functions?
Syntax: . (arguments);
39. How do you access member data?
Member data can be accessed in two ways.
a. Using the member functions.
b. Direct access through objects.
syntax: variable name =
40. What is nesting of member functions?
Calling of a member function from another member function of the same class is called nesting of member functions.
41. When is the memory space allocated for class?
The class doesn’t occupy any memory only the objects occupy the memory and is created only when the objects are declared.
42. What are the characteristics of a static member variable?
The following are the characteristics of a static member variable:
Static member variable is initialized to zero when the first object of class is created.
Visible only in the class.
Single copy of static member variable is created and used by all the objects of the class.
43. Why are the static member variables called class variables?
Static member variables are treated separately from a class object, and are related with a class directly, so they are called as class variables.
44. What are the characteristics of member functions?
The following are the characteristics of member functions:
Static member functions can be called directly using the class name.
Static member functions can access only static member variables or static member functions.
45. Write the syntax for accessing static member functions using class.
Syntax: :: ;
46. What is persistence?
Persistence is the property of object to persist in terms of identity, state and description regardless of the session that creates or utilizes them.
47. What is a modifier?
A modifier is a member function that changes the value of atleast one data member.
48. What is the other name for modifier?
Modifier is also called mutator.
49. What is an accessor?
The accessor is a function that doesn’t modify that state of an object.

50. What are arrays of objects?
Arrays of objects are the arrays of variables of type class.
51. How can you pass objects as function parameters?
Objects can be passed as function parameters in two ways:
Entire object is passes as a copy.
Only address of the object is passed.
52. What do you mean pass by value in terms of object?
Pass by value is the way of passing objects as function parameters in which only a copy of the object is passed and any changes made to the object inside the function doesn’t reflect in the original program.
53. What do you mean by pass by reference in terms of object?
Pass by reference is the way of passing objects as function parameters in which any changes made in the passed object reflect in the original object.
54. Which of the following is more useful “pass by value” or “pass by reference”?
Pass by reference is more useful because in this only address of the object is passed which avoids the need to send entire object.
55. What is the use of friend functions?
Friend functions are used to access the private members of a class, although it is not a member function of that class.
56. What are the characteristics of friend functions?
The following are the characteristics of friend functions:
It cannot access member variables directly and has to use object to do so.
It cannot be called using the object as it a normal function.
It has the objects as arguments.
It can be declared under any visibility label.
57. Write the syntax of friend function.
Syntax:
class
{
………..
………..
public:
friend void (arguments);
};
58. What is forward declaration?
When a function is used as a friend for 2 classes, as it takes arguments of 2 classes, the compiler is not aware of the 2nd class which is not declared, so Inorder to acknowledge the compiler about it, the 2nd class is declared at the beginning of the program, this declaration is called forward declaration.
59. Write the syntax of friend function using 2 classes.
class ; //forward declaration
class
{
………..
friend void (, );
};
class
{
……….
friend void (, );
};
void (arguments)
{
……….
}
60. Write the syntax for defining a pointer to a member variable?
Syntax: int ::* = & :: ;
61. What are local classes?
Classes defined inside a function or blocks are called local classes.
62. What are the limitations of local classes?
The following are the limitations of local classes:
Member functions should be defined inside the class.
Local classes cannot have static members.
The function in which local class is defined cannot access the private data of local class.
63. How can you make a member function constant?
Member function can be made constant by appending const keyword to the function prototype.
And these member functions cannot alter any data of the class.
64. Write the syntax for making a function constant.
Syntax: (arguments) const;
65. What is the use of the keyword mutable?
If there is a const object or function in which we require to modify a data item, then we can declare that data item as mutable so that we can modify it.
66. How is automatic initialization of objects done in C++?
Automatic initialization of objects is done using constructors.
67. What is a constructor?
Constructor is a member function which is used to initialize member data when the objects of the class are created.
68. What are the characteristics of a constructor?
The following are the characteristics of a constructor:
Constructor name should be same as class name.
It should be declared in public section.
It cannot return values.
Constructor is invoked automatically when objects are created.
It cannot be virtual.
It cannot be inherited.
Constructor can invoke new and delete for memory allocation.
Constructor address cannot be referred.
69. What is a default constructor?
A constructor without any arguments is called default constructor.
70. What are the types of constructors?
The following are the types of constructors:
Simple constructor
Parameterized constructor
Overloaded constructor
Copy constructor
Constructors with default arguments
Dynamic constructors
71. Write the syntax for simple constructor.
Syntax:
class
{
…………
public:
{ } //Simple constructor
};
72. Given an example for constructor.
class sum
{
int a, b;
public:
sum()
{
a=3;
b=4;
}
…………
};
73. What are parameterized constructors?
Parameterized constructors are the ones which can take arguments.
74. Write the syntax for parameterized constructor.
Syntax:
class
{
variable declaration;
public:
(arguments)
{
………..
}
};
75. Give an example for parameterized constructor.
class sum
{
int a, b;
public:
sum (int c, int d)
{
a=c;
b=d;
}
……………
};
76. What are the ways of passing arguments to constructors?
Arguments can be passed to constructors in 2 ways:
Explicit calling of constructor.
Ex. : sum s = sum(3, 4);
Implicit calling of constructor
Ex.: sum s(3, 4);
77. What are overloaded constructors?
Overloaded constructors are the one which share the same class name.
78. Give an example for overloaded constructors.
Ex.:
class sum
{
int a, b;
public:
sum () { }
sum (int a) {….}
sum (int a, int b) {……}
………………..
};
79. Give an example for constructor with default arguments.
Ex.:
sum (int a, int b=5) //constructor with default arguments
{
……….
}
……….
sum s(3); // value 5 is assigned for 2nd variable
80. What is copy constructor?
Copy constructor is used to declare and initialize objects from another object.
81. What is the limitation of copy constructor?
The limitation is that copy constructor is that copies the class object directly i.e., if the file has file pointers or dynamic memory allocation it will point to the same location.
82. What is copy initialization?
Copy initialization is the initialization process through copy constructor.
83. What are dynamic constructors?
The constructors which allocate memory at the time of creation of objects are called dynamic constructors.
84. What is the use of explicit keyword?
Explicit keyword is used to declare the construction to make the conversion explicit and a constructor declared as explicit cannot perform implicit conversion.
85. Write syntax for creating constant objects.
Syntax: const (arguments).
86. What is the limitation of constant objects?
A constant object can call only constant member functions.
87. What is a destructor?
Destructor is used to destroy the objects and release the memory occupied by the objects.
88. Write the syntax to call a destructor explicitly.
Syntax:
.~ ();
89. Can you overload a destructor?
No, a destructor cannot be overloaded.
90. How do you invoke a destructor?
Destructors are invoked automatically as and when the corresponding object is destroyed.
91. What is the use of member assignment operator?
Member assignment operator is used to copy a source object to the invoking target object in an assignment statement.
92. What is operator overloading?
Adding a special meaning to an operator apart from its normal function is called operator overloading.
93. What are the steps involved in operator overloading?
Operator overloading involves following steps:
Creation of class.
Declaring operator function in public section.
Defining the operator function.
94. Write the syntax of operator function.
Syntax:
:: operator op (arguments)
{
…………..
}
95. List the operators which cannot be overloaded.
The following are the list of operators that cannot be overloaded:
Scope resolution operator (::)
Sizeof operator
Class member access operators (., .*)
Conditional operator (?:)
96. When we use operator overloading do we use pass by reference or pass by value?
When operator overloading is used, we should use pass by reference.
97. What is the difference between friend functions and member functions when we overload binary operators?
When we overload binary operators member function requires only argument to be passed and friend function requires two arguments.
98. What is the difference between friend functions and member functions when we overload unary operators?
When we overload unary operators member function doesn’t require any arguments whereas friend function takes one argument.
99. Which operand is used to invoke operator function when we overload binary operator?
When we overload binary operator left hand operand is used to invoke operator function.
100. Which operand is used as an argument when we overload binary operator?
When we overload binary operator right hand operand is used as an argument.
101. What are the rules for overloading operators?
The following are the rules for overloading operators:
Basic meaning of operator cannot be changed.
Only the existing operators are overloaded.
Not all the operators can be overloaded.
Syntax rules of actual operators are to be followed.
102. Which operators cannot be used with friend functions for overloading?
The following operators cannot be overload when we use friend functions:
Assignment operator, function call operator, class member access operator, subscript operator.
103. Write the syntax for overloaded casting operator function.
Syntax:
operator ()
{
………
………
}
104. What is the difference between operator overloading and function overloading?
The difference is that operator overloading adds a special meaning to an operator apart from its normal function whereas function overloading defines many functions with same name but with different signatures.
105. When does a name clash occur?
A name clash occurs when a name is defined in more than place. Suppose if you use two different class libraries, there may be two classes with same name.
106. What are the conditions to be satisfied by conversion function?
The following conditions are to be satisfied by the conversion function:
It should be a class member.
It should be without any arguments.
There should be no return type.
107. Does C++ support automatic type conversion when we use user defined data types?
No, C++ doesn’t support automatic type conversion when we use user defined data types, they should be designed manually.
108. What is inheritance?
Inheritance is the process of creating a new class from an existing class.
109. What do you call the new class and the old class?
The new class is called derived class or subclass or child class and the old class is called base class or super class or parent class.
110. What is the use of inheritance?
Inheritance helps in code reusability, saves time and cost, and provides reliability.
111. Write the syntax for derived class?
Syntax:
class : visibility label
{
……..
……..
}
112. What are the types of visibility labels?
Private, protected and public are the visibility labels.
113. What does the visibility limit specify in the derived class definition?
Visibility limit specifies how the features of base class are derived depending on the visibility mode, and also specifies whether the derived class can be further derived or not.
114. What is the default visibility mode in the derived class definition?
Private.
115. What are the types of inheritance?
Inheritance is of 5 types:
Single, multiple, hierarchical, multilevel and hybrid inheritance.
116. What is single inheritance?
A subclass with only base class is called single inheritance.
117. What is multiple inheritance?
A child class with many parent classes is called multiple inheritance.
118. What is hierarchical inheritance?
Many child classes with one base class is called hierarchical inheritance.
119. What is multilevel inheritance?
The process of deriving a class from already derived class is called multilevel inheritance.
120. What is hybrid inheritance?
When two or more types of inheritance are used together, then it is called hybrid inheritance.
121. Write the syntax for single inheritance?
Syntax:
class
{
………
………
};
class :[visibility mode]
{
……...
………
};
122. How is the accessibility affected when a base class is inherited privately?
When a base class is inherited privately by the derived class, the private members of the base class become inaccessible to the derived class. And the public members of the base class become private members of the derived class.
123. How is the accessibility affected when a base class is inherited publicly?
When a base class is inherited publicly by the derived class, the public members of the base class become the public members of the derived class. The private members of the base class are not inherited, i.e., they are not accessible by the member functions of the derived class. But, they can be accessed using the derived member functions of base class.
124. How can you inherit the private members of the base class?
The private members of the base class can be inherited by using the visibility label protected for the private members.
125. How is the accessibility of protected data affected when a base class is inherited privately?
When the protected data is inherited privately, it becomes private in the derived class and cannot be inherited further.
126. How is the accessibility of protected data affected when a base class is inherited publicly?
When the protected data is inherited publicly, it becomes protected in the derived class and available for further inheritance.
127. How is the accessibility of data affected in protected derivation?
When we use protected derivation, the private members are not inherited whereas both the protected and public members become protected in the derived class.
128. Write the syntax for multilevel inheritance?
Syntax:
class
{
…….
};
class : [visibility mode]
{
……..
};
class : [visibility mode]
{
………
};
129. Give an example for multilevel inheritance.
Ex.:
class student
{
…….
};
class marks : public student
{
………
};
class grade : public marks
{
………
};
130. Write the syntax for multiple inheritance.
Syntax:
class
{
……..
};
class
{
……….
};
class
{
………
};
class :[visibility] , [visibility], [visibility]
{
……….
};
131. Give an example for multiple inheritance.
Ex.:
class skill1
{
……..
};
class skill2
{
………
};
class skill3
{
………..
};
class student: public skill1, public skill2, public skill3
{
……….
};
132. What is the use of class resolution operator?
Class resolution operator is to remove the ambiguity when two functions with the same name are to be called in derived class. In such situations by using the class resolution operator, we can call only the function of the desired class.
133. Give an example for class resolution operator.
Ex.:
class skill1
{
……..
void show () {………}
};
class skill2
{
………
void show () {……….}
};
class skill3
{
………..
void show () {……….}
};
class student: public skill1, public skill2, public skill3
{
……….
skill1 :: show (); //class resolution operator
skill2 :: show ();
skill3 :: show ();
………..
};
134. Write the syntax for hierarchical inheritance.
class
{
………..
};
class : [visibility]
{
…………
};

class : [visibility]
{
…………
};
class : [visibility]
{
…………
};
135. Give an example for hierarchical inheritance.
class institute
{
……..
};
class skill1 : public institute
{
………
};
class skill2 : public institute
{
………
};
class skill3 : public institute
{
………
};
136. Give an example for hybrid inheritance.
class A
{
………..
};
class B : public A
{
……….
};
class C : public A
{
…………
};
class D : public B, public C
{
………..
};
137. What is indirect base class?
The base class whose properties will be inherited to the derived class through the other derived classes is called indirect base class.
138. What is proper inheritance?
The inheritance in which the derived class is able to follow the path of base class without any ambiguity is called proper inheritance.
139. How can you overcome the multiple inheritance paths to a child class?
Multiple inheritance paths to a child class can be overcome by making the base class as virtual in intermediate class.
140. What is improper inheritance?
The inheritance in which a base class is used just for code reuse is called improper inheritance.

141. What is the need to make a base class as virtual in inheritance?
Generally, when a child class is derived from two parent classes which are in turn derived from a single base class, the members of the base class are duplicated in the child class via the parent classes and an ambiguity might be raised. Inorder to avoid this situation if we declare the base class as virtual in the intermediate (parent) class declaration, the data won’t be duplicated.
142. Give an example for virtual base classes.
Ex.:
class A
{
………
};
class B: public virtual A
{
……..
};
class C: virtual public A
{
………
};
class D: public B, public C
{
……..
};
143. What is an abstract class?
An abstract class is the one which is used just to get inherited but is not used to create objects.
144. How does the constructors execute in multilevel inheritance?
In case of multilevel inheritance, the constructors get executed in the order in which they are inherited.
145. Give the order in which the constructors are executed for the following example.
class C : public A, public virtual B
{
…….
};
First the virtual base class constructor is invoked i.e., B class constructor, then A class constructor and then the derived class constructor C is executed.
146. Give the order in which the constructors are executed for the following example.
class C : public A, public B
{
…….
};
As it clearly known that constructors are invoked in the order of inheritance, first the class A constructor is invoked, then class B constructor and at last the derived class C constructor is invoked.
147. In which order are the destructors invoked?
Destructors are invoked in reverse order from the constructor calls.
148. What is overriding?
Overriding is the ability to change the definition of an inherited method or attribute in the derived class.
149. What is the difference between method overloading and method overriding?
Method overloading is defining multiple functions with same name but with different signatures whereas method overriding is rewriting the virtual method of the base class by the inherited class.
150. Write the syntax for initializing member data using initialization list in the constructors.
Syntax:
(arguments) : initialization list
{
………
}
151. Give an example for initializing member data using initializing list in the constructors.
Ex.:
class A
{
int c, d;
……….
A (int x, int y): c(x), d (y)
{ }
……..
};
152. What is containership?
Possessing of objects of other classes in a class is called containership or nesting.
153. Give an example for containership.
Ex.:
class A
{
…….
};
class B
{
…….
};
class C
{
A a1;
B b1;
……
};


Continuation from last mail:
154. What is early binding?
Binding of an object to the corresponding function at compile time is called early binding.
155. What are the other names for early binding?
Early binding is also called compile time polymorphism or static binding or static linking.
156. What is polymorphism?
Polymorphism means a single name with multiple forms.
157. What are the types of polymorphism?
Polymorphism is of two types: Compile time polymorphism and run time polymorphism.
158. What is run time polymorphism?
Binding of an object to the corresponding function at run time is called run time polymorphism.
159. What are the other names for run time polymorphism?
Run time polymorphism is also called late binding or dynamic binding.
160. What are pointer variables?
Variables that hold memory addresses are called pointer variables.
161. What are pointer constants?
Pointer constants are the memory addresses in a computer which cannot be changed.
162. Write the syntax for declaring pointer variable.
Syntax: data type *;
163. Write the syntax for initializing a pointer variable.
data type *, var;
= &var;
164. What is ‘&’ operator called as?
‘&’ is called address of or reference operator.
165. What are null pointers?
Null pointers are the one which are not initialized in the program.
166. What is the use of object pointers?
Object pointers are used to create objects at run time.
167. What is the difference between pointers and references?
The difference is that pointers can be initialized and assigned, whereas references can only be initialized.
168. What is an incomplete type?
Incomplete types are the pointers in which there is non availability of the implementation of the referenced location or it points to some location whose value is not available for modification.
169. What is a dangling pointer?
If you try to use the address of an object after its lift time is finished, then dangling pointer is raised.

170. What is a void pointer?
Void pointer is the pointer which can refer to variable of any data type.
171. What is the other name for void pointer?
Void pointer is also called generic pointer.
172. What is ‘*’ operator called as?
‘*” operator is called dereference operator or indirection operator.
173. Write the syntax for accessing the content of data variable.
Syntax: *;
174. List the arithmetic operations which can be performed on pointers.
The following are the arithmetic operations that can be performed on pointers:
a. Increment and decrement operations can be done on pointer variables.
b. Any integer value can be added or deducted from pointer variable.
c. Pointers can be compared using relational operators.
d. Addition of 2 pointer variables is not possible.
175. In which header file are the string handling functions stored?
In
176. What are C-strings or C-style strings?
The null terminated character arrays used to store and manipulate strings are called C-strings.
177. What is callback function?
Callback function is the pointer to a function.
178. What are the types of function pointers?
Function pointers are of two types:
Function pointers pointing to static member functions and
Function pointers pointing to non static member functions.
179. Write the syntax for function pointer.
Syntax: data type( *) ();
180. Which operator has higher precedence dot operator (.) or the indirection operator (*.)?
Dot operator (.) has the higher precedence than the indirection operator (*.).
181. What is “this” pointer?
The pointer that refers to an object that is currently invoking a member function is called this pointer.
182. What is the parameter that is added to every non static member function when it is called?
“this” pointer.
183. How can a base pointer access the members of a derived class?
Base pointer cannot access the members of the derived class but it point to the objects of the derived class.
184. What are the rules to be followed for creating virtual functions?
The following are some rules to be followed for creating virtual functions:
Virtual functions cannot be static members.
They should be members of some class.
They can be friend of other classes.
They need not be redefined in the derived class.
185. What is a pure virtual function?
A function which is defined in the base class but of no use is called pure virtual function.
186. What are abstract base classes?
Classes which cannot be used to create any objects are called abstract base classes.
187. What are “do-nothing” functions?
“Do-nothing” functions are the ones which are just defined but are not used.
188. What is a stream?
The interface between the program and the input/output devices is called a stream.
189. What is input stream?
The source stream which sends data to the program is called input stream.
190. What is output stream?
The destination stream which receives output from the program is called output stream.
191. What are stream classes?
The hierarchy of classes which are used to deal with console and disk files using different streams are called stream classes.
192. What is an adaptor class?
A function that has no functionality of own is called an adaptor class.
193. What is the other name for adaptor class?
Wrapper class.
194. In which class are the input/output operations related streams are stored?
In iostream class.
195. In which file are the objects cout and cin stored?
In iostream file.
196. In which class is the ‘>>’ operator overloaded?
‘>>’ operator is overloaded in the istream class.
197. In which class is the ‘<<’ operator overloaded?
‘<<’ operator is overloaded in the ostream class.
198. What is the limitation of ‘cin’?
Limitation of cin is that it cannot read multiple words.
199. Which member functions are used to handle single character I/O operations?
Get () and put () are the functions used to handle single character I/O operations.
200. Name the line oriented I/O functions.
Getline () and write () are the line oriented I/O functions.
201. Write the syntax for getline ().
Syntax: cin. getline (, size);
202. Write the syntax for write ().
Syntax: cout.write (, size);
203. List some ios format functions.
Width (), precision (), unsetf (), setf (), fill ().
204. What are manipulators?
The functions included in the I/O statements to alter the parameters of a stream are called manipulators.
205. What is the difference between ios member function and the manipulator?
The difference between ios member function and the manipulator is that ios member function returns the previous format state whereas manipulator doesn’t return it.
206. Write the syntax for creating a manipulator?
Syntax:
ostream & manipulator (ostream & output)
{
…….
…….
return output;
}
207. Write the syntax for using width ().
Syntax: cout.width();
208. Write the syntax for setf ().
Syntax:
cout.setf (arg, arg1);

FILES:
209. What is a file?
A file is a collection of related data stored on a disk.
210. Name the classes that define the file handling methods.
The classes that include the file handling methods are ifstream, ofstream, and fstream.
211. In which file are the classes that include the file handling methods exist?
Fstream.
212. What things are to be specified when we perform some operation on a file?
When ever we perform some operations on a file, we have to mention the filename, data structure being used, purpose of using the file, and the method of opening.
213. What is EOF?
EOF stands for End of File, which is used to check for the end of file when a file is being read.
214. What are the parts of a file name?
A file name includes a primary name and an optional period with an extension.
215. What are the ways of opening a file?
A file can be opened using the constructor function of the class and using the member function open () of the class.
216. What is the difference in opening the file using constructor function and open ()?
The difference in opening the file using constructor function and open () is that constructor function uses only one file whereas open () is used when we want to handle multiple files using one stream.
217. What are the steps required to initialize file steam objects?
The following are the steps required to initialize file stream objects:
A file stream is created to manage the I/O stream.
Initialize the file object with file name.
218. Write syntax for to open a file for input?
Syntax: ifstream (“”);
219. Write the syntax to open a file for output?
Syntax: ofstream (“”);
220. Write the syntax for closing a file/
Syntax: .close ();
221. Write the syntax to open multiple files using open ()?
Syntax:
file_stream stream_obj;
stream_obj. open (“”);
stream_obj. open (“”);
222. Give an example to open multiple files using open ()?
Ex.:
ofstream ofile;
ofile. Open (“file1”);
ofile. Open (“file2”);
223. In which class is the function eof () present?
Eof () is exist in the class ios.
224. Write the syntax of open () with arguments.
stream_obj. open (“”, mode);
225. What does the file mode parameter ios::binary mean?
It means the file to be opened is a binary file.
226. What does the file mode parameter ios::app mean?
File is to be opened for appending data to end of file.
227. What does the file mode parameter ios::nocreate mean?
If the file does not exist open fails.
228. What does the file mode parameter ios::trunc mean?
File contents are to be deleted, if the file exists.
229. What is the default value for the file mode ios::in?
The default value for ios::in is open for reading only.
230. What is the default value for the file mode ios::out?
The default value for ios::out is open for writing only.
231. What is the difference between ios::ate and ios::app mode?
The difference between ios::ate and ios::app mode is that ios::ate mode allows us to add data or change data anywhere in the file whereas ios::app mode allows us to add data only to the end of file.
232. When you open a file in ios::out mode, what is the other mode opened by default?
When you open a file in ios::out mode, the file also gets opened by default in ios::trunc mode.
233. What is the use of file pointers?
File pointers are used to move in the file while writing or reading.
234. What are the types of file pointers?
File pointers are of two types: Input pointer and output pointer.
235. What are the other names for input pointer and output pointer?
Input pointer is also called get pointer and the output pointer is also called put pointer.
236. What is the use of input pointer?
The input pointer is used to read the contents in a particular file location.
237. What is the use of output pointer?
The output pointer is used to write the contents in a particular file location.
238. What is the default location to which the input pointer points to when a file is opened in read only mode?
At the beginning of the file.
239. What is the default location to which the output pointer points to when a file is opened in write only mode?
File pointer points to the beginning of the file before which it deletes all the contents of the existing file.
240. In which is the file to be opened to add data to the existing contents?
In append mode.
241. List the functions which are used to control the movement of file pointers?
seekg (), seekp (), tellg () and tellp () are the functions used to control the movement of file pointers.
242. What is the use of seekg ()?
seekg () is used to move input/get pointer to specified position.
243. What is the use of seekp ()?
seekp () is used to move output/put pointer to a specified position.
244. What is the use of tellg ()?
tellg () provides the current position of input/get pointer.
245. What is the use of tellp ()?
tellp () provides the current position of output/put pointer.
246. Write the syntax for seekg () with one and with 2 arguments?
Syntax:
.seekg(no of bytes); //with one argument
.seekg(offset, refposition); //with two arguments
Refposition is the location from where the file pointer moves to the specified offset position.
247. Write the syntax for seekp () with one and with 2 arguments?
Syntax:
.seekp(no of bytes); //with one argument
.seekp(offset, refposition); //with two arguments
Refposition is the location from where the file pointer moves to the specified offset position.
248. What are the types of constants used by refposition of seekg () and seekp ()?
refposition of seekg () and seekp () takes the following constants:
ios::beg – starting of file
ios::cur – current position of file pointer
ios::end – end of file
249. What are the functions used to handle single character at a time?
put () and get () are the functions used to handle single character at a time.
250. What are the functions used to handle blocks of data?
read () and write () are the functions used to handle blocks of data.
251. Write the syntax for write () and read ()?
Syntax:
.write ((char *) & , size of (variable));
.read ((char *) & , size of (variable));
252. List the error handling functions.
eof (), bad (), good () and fail () are the error handling functions.
253. In which class are the error handling functions present?
Error handling functions are present in the class ios.
254. Name the arguments main () can take?
Main () can takes the arguments argc (argument counter) and argv (argument vector).
255. Write the syntax for using command line arguments.
main (int argc, char * argv [])
256. What are command line arguments?
Command line arguments are given after the name of a program in command line operating systems like Dos or Linux, and are passed in to the program from the operating system.
257. What is the use of templates?
Templates are used to create generic classes and functions.
258. What is generic programming?
The method in which generic types are used as arguments in algorithms for different data types and data structures is called generic programming.
259. What is the other name for templates?
Templates are also called parameterized classes or functions.
260. What are parameterized macros?
Parameterized macros are the one which consist of template with insertion points for the addition of parameters.
261. Write the syntax for using template.
Syntax:
template
class
{

…………..
…………..
};
262. What is template class?
The class created from template is called template class.
263. Write the syntax for object of template class?
Syntax:
(arguments);
264. Write the syntax for using multiple generic types in class template.
Syntax:
template
class
{
………….
………….
};
265. Write the syntax for function template.
Syntax:
template
return type (arguments of type T)
{
…………
…………
}
266. Can the template functions be overloaded?
Yes, the template functions can be overloaded.
267. What are the steps in overloading template?
The following are the steps to overload a template:
a. call a normal function with an exact match.
b. call a template function which could be created with an exact match.
c. Follow overloading resolution to normal functions and use the one that matches.
268. Write the syntax for member function templates.
Syntax:
template
return type :: (parameters)
{
…………
…………
}
269. What is the use of template classes and functions?
Template classes and functions are used to eliminate redundancy of code and help in easier program development.
270. What is the difference between a template class and class template?
Template class is a parameterized class not instantiated until the client provides the needed information. A class template specifies how individual classes can be constructed.
271. What is the use of export?
Export is used to instantiate the non inline template classes and functions from different files.
272. What is the use of using?
Using is a namespace scope directive used to declare the accessibility of identifiers declared within a namespace scope.
273. What are the different types of errors encountered with a program?
The following are the different types of errors encountered in a program:
Syntax errors: violation of syntax rules
Run-time errors : mismatch of data, out of range data etc
Logical errors : logically incorrect data
Latent errors : show up only with a particular set of data.
274. What is an exception?
Exception is a run time anomaly or unusual situation that a program encounters while executing.
275. What are the types of exceptions?
Synchronous exceptions and asynchronous exceptions are the type of exceptions.
276. Give examples for synchronous exceptions.
Out of range index, division by zero, overflow etc.
277. What is overflow error?
Overflow error is an arithmetic error caused by the result of an arithmetic operation being greater than the actual space provided by the system.
278. Give an example for asynchronous exceptions.
Keyboard interrupt.
279. What is the use of exception handling?
Exception handling is used to detect exceptions so that a corresponding action can be taken.
280. What are the basic segments of error handling code?
Error handling code consists of two segments one for detecting and throwing exception and the other for catching the exception.
281. What are the steps involved in exception handling?
The following 4 steps are involved in exception handling:
Hit, throw, catch and handle.
282. What is the use of try block?
Try block is used to generate exceptions.
283. What is the use of catch block?
Catch block is used to catch the exceptions thrown by throw statement and handle the exceptions.
284. Write the syntax for try block?
Syntax:
try
{
………..
……….
throw exception;
……….
}
285. Write the syntax for catch block?
Syntax:
catch (data type )
{
………….
………….
}
286. Write the different forms of throw.
The following are the different forms of throw:
throw (exception);
throw exception;
throw;
287. How can you catch all the exceptions without specifying individually?
All the exceptions can be caught without specifying them individually by using ellipsis with catch.
Syntax:
catch (…)
{
………
………
}
288. Write the syntax for exception specification.
Syntax:
type (parameters) throw (type list)
{
……….
……….
}
289. What is translation?
Translation is creation of a new program in an alternate language which is logically equivalent the source language program.
290. What is the difference between ANSI C++ and Visual C++?
ANSI C++ is the earlier version of C++ whereas visual C++ is an IDE for developing GUI based applications.
291. What are the tools added to the visual C++?
Foundation class library, application wizard, class wizard are the tools added to the visual C++.
292. What is the use of Microsoft foundation class library?
MFC library would help us reduce the code and development time.
293. What is the use of application wizard?
Application wizard provides a frame work for creating initial applications.
294. What is the use of class wizard?
Class wizard helps in customizing the classes.
295. What is an iterator class?
An iterator class is used to traverse through the objects maintained by a container class.




296.

297. DATA STRUCTURES:
1. What is an algorithm?
The process of providing solution to a problem in a sequence of steps is called an algorithm.
2. What are the properties of an algorithm?
An algorithm must possess the following properties:
a. It should get input data.
b. It should produce output.
c. The algorithm should terminate.
d. Algorithm should be clear to understand.
e. It should be easy to perform.
3. What are the types of algorithms?
Algorithms are of two types: repetitive and recursive algorithms.
4. Define iterative algorithms.
Algorithms which use loops and conditions to solve the problem are called iterative algorithms.
5. Define recursive algorithms.
Algorithms which perform the recursive steps in a divide and conquer method are called recursive algorithms.
6. What is an array?
An array is a sequential collection of same kind of data elements.
7. What is a data structure?
A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms for the manipulation of data.
8. Name the areas of application of data structures.
The following are the areas of application of data structures:
a. Compiler design
b. Operating system
c. Statistical analysis package
d. DBMS
e. Numerical analysis
f. Simulation
g. Artificial Intelligence
h. Graphics
9. What are the major data structures used in the following areas: Network data model, Hierarchical data model, and RDBMS?
The major data structures used in the above areas are:
Network data model – Graph
Hierarchical data model – Trees
RDBMS – Array
10. What are the types of data structures?
Data structures are of two types: Linear and non linear data structures.
11. What is a linear data structure?
If the elements of a data structure are stored sequentially, then it is a linear data structure.
12. What is non linear data structure?
If the elements of a data structure are not stored in sequential order, then it is a non linear data structure.
13. What are the types of array operations?
The following are the operations which can be performed on an array:
Insertion, Deletion, Search, Sorting, Merging, Reversing and Traversal.
14. What is a matrix?
An array of two dimensions is called a matrix.
15. What are the types of matrix operations?
The following are the types of matrix operations:
Addition, multiplication, transposition, finding determinant of square matrix, subtraction, checking whether it is singular matrix or not etc..
16. What is the condition to be checked for the multiplication of two matrices?
If matrices are to be multiplied, the number of columns of first matrix should be equal to the number of rows of second matrix.
17. Write the syntax for multiplication of matrices?
Syntax:
for (=0; < value;++)
{
for (=0; < value;++)
{
for (=0; < value;++)
{
arr[var1][var2] += arr[var1][var3] * arr[var3][arr2];
}
}
}
18. What is a string?
A sequential array of characters is called a string.
19. What is use terminating null character?
Null character is used to check the end of string.
20. What is an empty string?
A string with zero character is called an empty string.
21. What are the operations that can be performed on a string?
The following are the operations that can be performed on a string:
finding the length of string, copying string, string comparison, string concatenation, finding substrings etc.
22. What is Brute Force algorithm?
Algorithm used to search the contents by comparing each element of array is called Brute Force algorithm.
23. What are the limitations of arrays?
The following are the limitations of arrays:
Arrays are of fixed size.
Data elements are stored in continuous memory locations which may not be available always.
Adding and removing of elements is problematic because of shifting the locations.
24. How can you overcome the limitations of arrays?
Limitations of arrays can be solved by using the linked list.
25. What is a linked list?
Linked list is a data structure which store same kind of data elements but not in continuous memory locations and size is not fixed. The linked lists are related logically.
26. What is the difference between an array and a linked list?
The size of an array is fixed whereas size of linked list is variable.
In array the data elements are stored in continuous memory locations but in linked list it is non continuous memory locations.
Addition, removal of data is easy in linked list whereas in arrays it is complicated.
27. What is a node?
The data element of a linked list is called a node.
28. What does node consist of?
Node consists of two fields:
data field to store the element and link field to store the address of the next node.
29. Write the syntax of node creation?
Syntax:
struct node
{
data type ;
struct node *ptr; //pointer for link node
}temp;
30. Write the syntax for pointing to next node?
Syntax:
node->link=node1;
31. What are self referential structures?
The structures which contain a member field which point to the same structure type are called self referential structures.
32. How can you identify the end of a linked list?
In a linked list the link field of the last node stores the NULL value using which the end of the linked list is identified.
33. Write the syntax to identify the end of the linked list?
Syntax:
while (temp!=NULL)
{
……
}
34. How can you access the elements of a linked list?
The elements of a linked list can be accessed using the head pointer which points to the first node of the list and then by using the link field the next elements are accessed one by one until the last node is reached which is identified using the null pointer.
35. Write the algorithm for displaying the nodes of a linked list.
Algorithm:
i. Start with head node.
ii. While nodes are present or last node is not reached:
a. display the current data element.
b. move to next node.
36. What are the operations that can be performed on a linked list?
Addition, deletion, traversal, append, merge, sort, reverse, copy, search.
37. What are the situations in inserting a node?
When you want to insert a node, there are 3 situations encountered:
Insert at beginning of list, insert in the middle of list, insert at the end of list.
38. Write the algorithm for insertion of a node?
Algorithm:
Start
If the list is empty or new node should be added at beginning then,
insert the new node as head node,
else
if the new node should be inserted at the end then,
insert the new node at the end of list,
else
insert the new node in the middle of the list.
End
39. Write the algorithm for inserting node at the beginning of the linked list.
Algorithm:
a. Create space for new node.
b. Assign the value to the data field of new node.
c. Set the next field of the new node to the start of list.
d. Change the value of head pointer to point to new node.
40. Write the algorithm for inserting a new node in the middle of the list between specified values.
Algorithm:
a. Create space for new node.
b. Assign the value to the data field of new node.
c. Set the next field of new node to point to the value before which node should be inserted.
d. Set the next field of the value after which new node should be inserted to point to the new node.
41. Write the algorithm for inserting a node at the end of the list.
Algorithm:
a. Create space for new node.
b. Assign the value to the data field of new node.
c. Set the next field of the last node to the new node.
d. Set the next field of new node to null.
42. What are the situations in deleting a node?
Deletion of a node encounter the following situations:
Deletion of first item, deletion of the last item, deletion of a node between the specified nodes.
43. Write the syntax for deletion of a node.
Algorithm:
Start
If the list is empty then,
node cannot be deleted,
else
if the node to be deleted is the first node then,
make the head point to the second node,
else
delete the node from the list body
End
44. Write the algorithm for deleting the first node of the linked list.
Algorithm:
a. Check if the list is empty.
b. If the list is not empty make the head node point the next node.
45. Write the algorithm for deleting the last node.
Algorithm:
a. check if the list is empty.
b. If the list is not empty, traverse to the last but one node and set its next field to null.
46. Write the algorithm for deleting a specified node.
Algorithm:
a. Check if the list is empty.
b. If the list is not empty, traverse to the node after which the node to be deleted is present using the first loop.
c. And traverse to the node before which the node to be deleted is present using second loop.
d. Set the next field of first node to the node after the node to be deleted.
47. What are the advantages of a linked list?
As the linked list is dynamic data structure it can grow and shrink during program execution.
It doesn’t waste memory.
Flexibility in arranging data elements.
48. What are the applications of linked lists?
Linked lists are used to model different abstract data types like stacks, queues, trees etc.
49. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
Void pointer, because the heterogeneous linked list contains different data types in its nodes and we need a pointer to connect them, and we ordinary pointers cannot be used for this. So, we use void pointer which is capable of storing pointer to any type as it is a generic pointer type.
50. Is a linked list linear or non linear data structure?
According to access linked list is linear data structure, but according to storage it is non linear.
51. What are the types of linked lists?
Circular linked list, doubly linked list, circular doubly linked list are the types of linked lists.
52. What is the limitation of linked list?
The limitation of linked list is that we can traverse the list in only one direction, i.e., forward direction only. We cannot traverse the list back.
53. How can you overcome the limitation of linked list?
The limitation of linked list can be overcome by using the circular linked list.
54. What is a circular linked list?
Circular linked list is the list in which the last node points back to the first node instead of storing a null value.
55. How can you traverse a circular linked list?
The elements of a circular linked list can be accessed using the head pointer which points to the first node of the list and using the link field, next elements can be accessed. As there is no null pointer indicating the end of the list, a condition that last node is not equal to first node should be used to identify the end of the list.
56. What is recursion?
Recursion is the process of a function calling itself to complete a task.
57. What is the limitation of circular linked list?
The limitation of circular linked list is that if we want to access the previous node, the entire list has to be traversed again continuing from that node till that node.
58. How can you overcome the limitation of circular linked list?
The limitation of circular linked list can be overcome by using doubly linked list.
59. What is a doubly linked list?
The linked list in which each node has 3 fields, one data field, second pointing to the previous node and the third pointing to the next node, for the easy traversal in both the directions is called doubly linked list.
60. What are the operations that can be performed on doubly linked list?
Traversal of the list, add at beginning, add at end, add after n node, delete nth node, merge, sort, reverse, copy etc.
61. Using which data structure are the stacks and queues maintained?
Using linked list.
62. What is the disadvantage of doubly linked list in comparison to single linked list?
The disadvantage of doubly linked list in comparison to single linked list is that it occupies more memory than single linked list.
63. What is a circular doubly linked list?
The linked list in which there are both forward pointer and backward pointer in circular form is called circular doubly linked list.
64. What is a sparse matrix?
If a matrix has many zero elements then it is a sparse matrix.
65. Name few applications of multilinked data structure.
In index generation, sparse matrix etc.
66. What is a stack?
Stack is a data structure in which addition or deletion of the elements is done at the top.
67. What is the other name for stack?
Stack is also called Last in First out (LIFO) list.
68. What are the operations done on a stack?
Push and pop are the two operations which can be done on stack.
69. Define push.
The process of adding data element to the stack is called push.
70. Define pop.
The process of deleting a data element from the stack is called pop.
71. What are the ways of representing a stack?
A stack can be represented either as an array or as an linked list.
72. Write the algorithm of adding an element to a stack represented as an array.
Algorithm:
a. Check whether stack is full or not.
b. Increment the pointer pointing to the top of the stack.
c. Assign the value to the top index of the array.
73. Write the algorithm for removing an element from a stack represented as an array.
Algorithm:
a. Check whether stack is empty.
b. If stack is not empty, decrement the top pointer.
74. What is the limitation in representing a stack as an array?
An array has a fixed size whereas a stack doesn’t have any fixed size because of push and pop operations. So, fixed size becomes a limitation in representing a stack as an array.
75. Write the algorithm for push operation on stack represented as a linked list.
Algorithm:
a. Create space for new node.
b. Assign the value to the data field of new node.
c. Set the link field of new node to top;
d. Set the top to the new node.
76. Write the algorithm for pop operation on stack represented as a linked list.
Algorithm:
a. Check whether stack is empty.
b. If not empty traverse to the node below the top.
c. Set the top to the second node.
77. What are the applications of stacks?
The following are the applications of stacks:
In evaluation of expressions, unfolding systems recursive jobs, to find the traversals of graphs, non recursive traversal of binary trees, implementation of function calls, translating from one computer language to another etc.
78. Which data structure is used in recursion? Why?
Stack is the data structure used in recursion. Because stack follows the rule Last in first out (LIFO), and remembers its caller to return the value.
79. Where are the return values stored while using recursion?
Return addresses or return values of function calls are stored in system stack while using recursion.
80. What is stack overflow?
When you try to add an element to a stack which is already full, it results in stack overflow.
81. What is stack underflow?
When you try to remove an element from a stack which is empty, it results in stack underflow.
82. What is polish notation?
The notation which is used to represent an arithmetic expression is called polish notation and is named after a polish mathematician Jan Lukasiewicz.
83. What are the types of polish notations?
Polish notations are represents as prefix notation and postfix notation.
84. Which notations are used in evaluating arithmetic expressions using prefix and postfix forms?
Polish and Reverse Polish notations.
85. What is a queue?
Queue is a data structure in which insertion of element is done at one end and removal of element is done at the other end.
86. What is other name for queue?
Queue is also called as First in First out (FIFO) list.
87. What are the ways of representing a queue?
Queue can be represented either as an array or as a linked list.
88. What is front end?
The end of the queue at which insertion of data elements takes place is called front end.
89. What is rear end?
The end of the queue at which removal of data elements takes place is called rear end.
90. Write the algorithm of adding an element to a queue represented as an array.
Algorithm:
a. Check whether queue is full or not.
b. If the queue is empty then increment the front pointer and the rear pointer.
c. If the queue is not empty and not full then increment the rear pointer.
c. Assign the value to the rear index of the array.
91. Write the algorithm for removing an element from a queue represented as an array.
Algorithm:
a. Check whether queue is empty.
b. If queue is not empty, increment the front pointer.
c. If front and rear point to the same value then make both the pointers negative.
92. What are the applications of queues?
The following are the applications of queues:
Queues are used in a network with shared printers, fax etc and the jobs accumulate in a queue.
Queues are using in Operating system with GUI, windows and applications communication messages are placed in queue.
In messaging systems, event schedulers, in radix sort algorithm etc.
93. What is the limitation in representing a queue as an array?
An array has a fixed size whereas a queue doesn’t have any fixed size because of addition and deletion operations. So, fixed size becomes a limitation in representing a queue as an array.
94. Write the syntax of node creation for queue?
Syntax:
struct node
{
data type ;
node *link; //field where next node address is stored
}*front, *rear; // front and rear end pointers
95. Write the algorithm for adding a data element to a queue represented as a linked list.
Algorithm:
a. Create space for new node.
b. Assign the value to the data field of new node.
c. Set the link field of new node to rear;
d. Set the rear to the new node.
96. Write the algorithm for removing a data element from a queue represented as a linked list.
Algorithm:
a. Check whether queue is empty.
b. If not empty then increment the front pointer.
c. If both front and rear point to same value then make them both negative.
97. What is queue overflow?
When you try to add an element to a queue which is already full, it results in queue overflow.
98. What is queue underflow?
When you try to remove an element from a queue which is empty, it results in queue underflow.
99. What is circular queue?
Circular queue is the one in which elements are added to the rear end till is full, then keeps adding data elements to the front end if it is free.
100. What do we need circular queue?
We need circular queue because when normal queue is represented as an array, when the rear has reached maximum array size it shows as full. But as the removal of elements is done from the front end even though the queue is empty it doesn’t show.
101. Write the algorithm of adding an element to a circular queue represented as an array.
Algorithm:
a. Check whether queue is full or not.
b. If the queue is empty then increment the front pointer and the rear pointer.
c. If the queue is not empty and not full then increment the rear pointer.
d. Assign the value to the rear index of the array.
e. If the queue is full check whether the front is free or not.
f. If the front is free then increment the front pointer.
g. Assign the value to the front index of the array.
102. What is a dequeue?
Dequeue is a double ended queue in which data elements can be added or deleted from both the ends.
103. What is a priority queue?
A priority queue is an abstract data type in which elements are stored according to their levels of priority.
104. What are the operations performed on a priority queue?
The following are the operations performed on a priority queue:
Adding an element with a particular priority.
Remove the element with the highest priority and return.
Peek at the highest priority element.
105. What are the rules followed in using a priority queue?
Data of higher priority is processed first.
If the same priority data is found, then the data first added to the queue is processed first.
106. Write the syntax of node creation for priority queue?
Syntax:
struct node
{
data type ;
int priority, order;
};
107. What is the minimum number of queues required to implement priority queue?
Two queues are required to implement priority queue. One for actual storing of data and other for storing priorities.
108. What are the applications of priority queues?
The following are the applications of priority queues:
Managing of limited resources like bandwidth, printers (in a network), in A* search algorithm, in discrete event simulation, scheduling jobs in OS etc.
109. What is a bounded queue?
A queue limited to a fixed number of items is called bounded queue.
110. What is a tree?
Tree is a non linear data structure in which each node may point to many nodes.
111. Name the applications of tree data structure.
The following are the applications of tree data structure:
a. In manipulation of arithmetic expression.
b. Symbol table construction.
c. Syntax analysis.
112. What is a binary tree?
The non linear data structure which has at the most two pointers to the other tree nodes is called binary tree.
113. What does a binary tree consist of ?
A binary tree consists of a root, the left sub tree and the right sub tree.
114. What is an empty binary tree?
A binary tree with no elements is called an empty binary tree.
115. What is a node?
The individual element of a tree is called a node.
116. What is a root?
The base node of a tree is called the root.
117. What is a leaf node?
A node that does not have any further nodes is called a leaf node.
118. What is a father node?
If A is root node of B, and B is the left or right sub node of it, then A is called father of B, and B is called left or right son of A.
119. What is an ancestor?
If a node A is father of some node C, or may be father of C’s father and further more, then A is said to be ancestor of C.
120. What is a left descendant?
If a node A is father of some node C, or may be father of C’s father and further more, then C is said to be descendant of A.
121. What is climbing of tree?
The traversal of tree from leaf node to root node is called climbing of tree.
122. What is descending of tree?
The traversal of tree from root node to leaf node is called descending of tree.
123. What is a strictly binary tree?
If every non leaf node in a binary tree has non empty left and right sub trees then it is called a strictly binary tree.
124. What is a degree of a node?
Degree of a node is the number of nodes connected to that node.
125. What is a level of tree?
The level of a tree is determined in terms of its distance from the root node where a root node has a level 0; a child node is one level more than the root node and so on.
126. What is depth of a tree?
Depth of a tree is the maximum level of any leaf node.
127. What is a complete binary tree?
Complete binary tree is a strict binary tree in which all the leaf nodes are at same level.
128. What is traversal of tree?
The process of visiting each node of a tree exactly once in a particular method is called traversal of a tree.
129. What is the efficient data structure used to implement tree?
Linked list.
130. What are the different methods of traversal of a tree?
The following are the different methods of traversal of a tree:
In-order , Pre-order and Post-order traversal.
131. What is the primary difference in the different methods of traversal?
The difference is only in the order in which the root node, nodes in the right sub tree, and the nodes in the right sub tree are visited.
132. Write the algorithm for in-order traversal.
Algorithm:
a. Traverse the left sub tree in in-order.
b. Visit the root.
c. Traverse the right sub tree in in-order.
133. Write the algorithm for pre-order traversal.
Algorithm:
a. Visit the root.
b. Traverse the left sub tree in pre-order.
c. Traverse the right sub tree in pre-order.
134. Write the algorithm for post-order traversal.
Algorithm:
a. Traverse the left sub tree in post-order.
b. Traverse the right sub tree in post-order.
c. Visit the root.
135. What are the elements of each node of a binary tree?
Node of a binary tree consists of a data field, a pointer to the right child, and a pointer to the left child.
136. Write the syntax for structure of a binary tree.
Syntax:
struct tree
{
tree *left;
int data;
tree *right;
};
137. What are the different ways in which a binary tree can be represented?
A binary tree can either be represented using links or by using arrays.
138. What is a binary search tree?
A tree in which all the elements in the right sub tree of a node n are greater than or equal to the contents of n and the elements in the left sub tree are less than the contents of n, then it is called a binary search tree.
139. What are the different operations that can be performed on a binary search tree?
Insertion, deletion and searching.
140. Write the algorithm for searching a node in a binary search tree?
Algorithm:
a. Data is compared with root node.
b. If it is not equal, then check if it is less than the root node, then follow the same steps for left sub tree.
c. If the value is greater than root node, then follow the same steps for right sub tree.
141. Write the algorithm for inserting a node in a binary search tree?
Algorithm:
a. First the data is compared with root node.
b. If it is greater than or equal to the root node, then follow the same steps to insert the data in right sub tree.
c. If the value is lesser than the root node, then follow the same steps to insert it in the left sub tree.
d. Steps a and (b or c) are repeated until an empty node is found where the data is to be inserted.
142. What are the possible conditions encountered in deleting data from a binary tree?
The following are the possible conditions:
a. Node with data has no children.
b. Node with data has only one child.
c. Node with data has two children.
143. What are the applications of binary tree?
The binary tree is used in situations where we want to make two way decisions, in using binary search trees, in representing expressions etc.
144. What are expression trees?
Expression trees are the arithmetic expression represented as binary trees.
145. If you traverse the expression tree in pre-order which type of expression is obtained?
Prefix expression.
146. If you traverse the expression tree in post-order which type of expression is obtained?
Postfix expression.
147. If you traverse the expression tree in in-order which type of expression is obtained?
Infix expression.
148. How do you convert a binary tree into an extended tree?
By adding new nodes to the leaf nodes of a binary tree and to the nodes that have only one child we can convert a binary tree into an extended tree.
149. What is the other name for extended tree?
2-tree.
150. What are internal nodes?
When a binary tree is converted to an extended tree, the nodes of the original tree are called internal nodes.
151. What are external nodes?
When a binary tree is converted to an extended tree, the nodded that are added to the binary tree are called external nodes.
152. How do you calculate the external nodes if the number of internal nodes are given?
The number of external nodes of a binary tree is always one more than the number of internal nodes. For example, if N is the number of internal nodes, then the external nodes are N+1.
153. How do you calculate the number of nodes of a binary tree, if the height of it is given?
If the height of a binary tree is given, the number of nodes is calculated by using 2h+1-1.
154. How do you calculate the number of branches of a tree if the number of nodes is given?
If the number of nodes is given, the number of branches of a tree is always less then it by 1.
155. What are right threads?
Right threads are the pointers that point in-order successor of a node.
156. What are left threads?
Left threads are the pointers that point to in-order predecessor of a node.
157. What is the limitation of threads in using binary tree?
The limitation of thread in using binary tree is in finding out whether a pointer is normal pointer to child or a thread that points back to in-order predecessor node or in-order successor node.
158. What are the elements of a node in threaded binary tree?
The following are the elements of a node in threaded binary tree:
Data, left pointer, right pointer, a true or false value for left thread, and a true or false value for right thread.
159. Write the syntax of threaded binary tree node?
Syntax:
struct tbtree
{
int data;
tbtree *leftchild;
tbtree *rightchild;
enum Boolean left;
enum Boolean right;
};
160. What are the conditions to be checked when deleting a node in threaded binary tree?
The following conditions are to be checked when deleting a node in threaded binary tree:
a. No node in tree should contain the specified data.
b. Node should have no children.
c. Node should have exactly one child.
d. Node should have two children.
161. What is a general tree?
A tree with n number of nodes is called a general tree.
162. What are siblings?
Siblings are the children of a node.
163. Name the pointers which are to be maintained in converting a general tree to a binary tree.
The pointers which are to be maintained in converting a general tree to a binary tree are:
i) A pointer pointing to first child of node.
ii) A pointer pointing to siblings of node.
164. Write the syntax of node of a general tree represented as a binary tree.
Syntax:
struct gtree
{
int data;
gtree *firstchild;
gtree *siblings;
};
165. What is a forest?
A set of trees which are not linked together is called a forest.
166. What is a balanced binary tree?
Balanced binary tree is the binary search tree in which the difference between the heights of left and right sub trees of all nodes is at most one.
167. What is the other name for balanced binary tree?
Balanced binary trees are also called AVL trees.
168. Why are balanced binary trees called AVL trees?
The balanced binary trees also called AVL trees are named after the Russian mathematicians G.M. Adelson-Velskii and E.M. Landis who invented them.
169. What are the elements of an AVL tree?
The AVL tree consists of data field, two fields for storing the left and right child address, and one field to hold balance factor.
170. How do you calculate the balance factor a node?
If you subtract the height of the right sub tree of node from the height of left sub tree we get the balance factor.
171. Write the syntax of AVL tree node?
Syntax:
struct AVL_tree
{
int data;
int bal_factor;
AVL_tree *left;
AVL_tree *right;
};
172. How do you check whether a tree is AVL tree or not, provided the balance factor is known?
If the balance factor of any node is -1, 0 or 1 then only it is an AVL tree otherwise not.
173. How can you represent balance factor apart from using -1, 0 or 1?
Apart from using -1, 0, or 1 we can also represent balance factor using \, -, /.
174. How can you determine whether right sub tree has more height or left sub tree has more height?
It can be done using the balance factor value:
If it is -1, right sub tree has more height than the left sub tree.
If it is 1, left sub tree has more height than the right sub tree.
If it 0, both are of equal height.
175. At what condition the balancing has to be done in AVL tree?
When the height factor is greater than 1 or less than -1.
176. What is the disadvantage of AVL trees?
The disadvantage of AVL trees is that insertion and deletion needs rotation which is complicated.
177. How can you overcome the disadvantage of AVL tree?
The disadvantage of AVL trees can be overcome using 2-3 trees data structure.
178. What are the conditions to be followed to build 2-3trees?
The following are the conditions to be followed to build 2-3trees:
a. The leaf nodes should have two or three non-empty child nodes which are in turn 2-3trees.
b. One single node can contain either one or two values.
c. All the leaf nodes should be at same level.
d. If a node has two children, then it contains single data, and data value of left sub tree should be less than the node, and data value of right sub tree should be greater than the node.
e. If a node has three children, then node contains two data values. And the data of left sub tree nodes should be less than first data value, and data of middle sub tree should be greater than first data value and less than second data value, and data of right sub tree should be greater than first data value and second data value.
179. Write the syntax of 2-3tree node?
Syntax:
struct two_three
{
int count;
int data[3];
two_three *child[4];
};
180. What is a multiway tree?
A tree of order n is a multiway tree if any node contains maximum n-1 values and has maximum n children.
181. What is a B-tree?
If a multi way search tree of order n meet the following criteria then it a B-tree.
a. All non-leaf nodes have atleast n/2 children and at most n children.
b. A non-leaf node may have at most n non-empty child.
c. A root node with no child is possible.
d. If there are n children of a node, then it must have n-1 data values.
e. All values of left child are less than first value of node, and all values of right node are greater than last value of node.
f. All leaf nodes should appear on same level.
182. Write the syntax of B-tree node?
Syntax:
struct btree
{
int count;
int value[max + 1];
btree *child[max + 1];
};
Where
count – number of children of a node
value – values of node
child – stores addresses of child node
max – maximum number of node values
183. What is the data structure used in internal storage representation in RDBMS?
B+ tree in which all the data is stored only in leaf nodes.
184. Using which structure is the priority queue implemented?
Using heap.
185. What is a heap?
A complete binary tree is called a heap.
186. What are the types of heaps?
Max heap and min heap are the types of heaps.
187. What is max heap?
A tree in which the value at any node is greater than all its children then it is called max heap.
188. What is min heap?
A tree in which the value at any node is less than all its children then it is called min heap.
189. What is the other name for max heap?
Descending heap.
190. What is the other name for min heap?
Ascending heap.
191. Name the operations that can be performed on a heap.
Insertion, deletion, and replacement of a node are the operations of a heap.
192. What is searching?
The process of finding out the position of a given value in a list is called searching.
193. What is linear search?
Linear search is the process of the searching for an element right from the 0th element of a list till the end of the list or until the element is found.
194. Write the syntax for linear search using unsorted array?
Syntax:
()
{
for (var=0; var{
if (arr[var] == value)
………
}
……..
}
195. Write the syntax for linear search using sorted array?
Syntax:
()
{
for (var=0; var{
if (arr[size-1]=num)
{
if (arr[var] == value)
………
}
……..
}
}
196. What is the condition to use binary search?
To use a binary search the list should be in a sorted order.
197. Write the algorithm for binary search?
Algorithm:
a. Compare the value with the mid value of list.
b. If not equal, then divide the list into two halves; one half from 0th element to mid element -1 and other element from mid element + 1 to the last element.
c. Steps a and b are repeated individually with each halves until the element is found.
198. What is the advantage of binary search compared to linear search?
Binary search executes very fast compared to linear search because of less number of comparisons.
199. What is the disadvantage of binary search?
The disadvantage is that the list should be sorted, if not linear search is to be used.
200. What is sorting?
Sorting is arranging of data in a particular order.
201. What are the types of sorting?
Sorting is of two types: Internal and external sorting.
202. When should we use internal sorting?
Internal sorting can be used when all the data can be kept at a time in memory.
203. When should we use external sorting?
External sorting should be used when the data is huge and cannot be kept in memory at a time and has to use auxiliary memory.
204. What are the types of internal sorting?
Bubble sort, Selection sort, Insertion sort, Heap sort, Merge sort, Shell sort are the types of internal sorting.
205. Write the algorithm for bubble sort.
Algorithm (ascending order):
a. Start with first element and compare with next element.
b. If first element is greater than next, then they are interchanged.
c. All the elements are compared in the same way with their next element except the last element, which results in large element.
d. Repeat the steps a, b, and c excluding the last element bubbled out in that iteration.
206. Why is the term bubble used in bubble sort?
The bubble sort in its iterations causes larger values to "bubble" to the end of the list and smaller values "sink" towards the beginning of the list, thus the name bubble sort.
207. What is the complexity of bubble sort?
O (n2).
208. Why the complexity of bubble sort is same in all the scenarios (worst, average, and best)?
The reason is that the code has no way of determining whether the list is already in order.
209. How can you solve the limitation of bubble sort?
The limitation of bubble sort can be solved using modified bubble sort which uses a flag to check whether list is sorted or not.
210. What is the use of modified bubble sort?
Modified bubble sort has a flag which is set to check if a swap is done after an entire pass over the array. If no swap is done, then it is clear that the list is already in order because no two elements need to be switched. In that case, the sort should end.
211. What is the best case complexity for modified bubble sort?
The complexity for best case for modified bubble sort is O (n).
212. Write the algorithm for selection sort.
Algorithm:
a. Start with the first element and compare with all the other elements in the list.
b. If the next element is less than the first element, then they are swapped.
c. At the end of iteration smallest element is placed in the beginning of list.
d. Steps a, b are repeated with 2nd, 3rd, and so on elements until the last but one element.
213. What is the complexity of selection sort?
O (n2).
214. Write the algorithm for insertion sort.
Algorithm:
a. In first iteration, 1st element is compared with 0th element.
b. Likewise in the nth iteration, nth element is compared with the elements below it starting from 0th element.
c. In this iterations, if it is found that to be inserted element can be inserted anywhere space is created by shifting the other elements one position to right.
215. What is the complexity of insertion sort?
For worst and average cases it is O (n2) and for best case it is n-1.
216. What is logic of quick sort?
Quick sort uses the divide and conquer recursive algorithm.
217. Write the algorithm for quick sort?
Algorithm:
a. Pick an element in the array to use as a pivot element.
b. Split the array into two parts: one with elements greater than pivot element and the other with elements less than the pivot element.
c. Repeat the above steps for both halves of the original array.
218. What is the other name for quick sort?
Partition exchange sort.
219. What is the complexity of quick sort?
Worst case - O (n2), average case – log2n, best case – log2n.
220. Write the algorithm for heap sort?
Algorithm:
a. First step is building a heap out of the data set.
b. Then remove the largest item and place it at the end of the sorted array.
c. Next reconstruct the heap and remove the largest remaining item and place it in the next open position from the end of the sorted array.
d. This is repeated until there are no items left in the heap and the sorted array is full.
221. How many arrays are used in heap sort?
Heap sort uses two arrays - one to hold the heap and the other to hold the sorted elements.
222. Out of the following which is the slower sort: merge, quick and heap?
Heap.
223. What do you mean by “In place”?
Sorting methods that do not require additional space are called “In place”.
224. What is the complexity of heap sort?
Worst case - O (n log n), average case – O (n log n), best case – O (n log n).
225. Write the algorithm for merge sort.
Merge sort either merges 2 already sorted lists or to sort huge data, divides the list into smaller lists using divide and conquer method.
Algorithm:
a. First split the list into two equal halves and place them in separate arrays.
b. Each array is recursively sorted.
c. Then the elements from both the sorted arrays are compared and smaller of both the elements is placed in third array.
d. Sorting is done when all the elements from both the elements are placed in third array.
226. What is the complexity of merge sort?
O (n log n) for all the cases.
227. How many arrays are required for merge sort?
Three arrays (one for each half of data set and the other for the sorted list).
228. What are the other names for shell sort?
Shell sort is also called diminishing increment sort or comb sort.
229. What is logic followed by shell sort?
The shell sort makes multiple passes through the list, and each time it sorts equal sized sets using insertion sort. The size of the set to be sorted becomes larger with each pass through the list, until it consist the entire list.
230. Which of the following algorithms is slower: merge, heap, shell, quick?
Shell sort.
231. What are the methods available to store sequential files?
The following are the methods used to store sequential files:
a. Straight merge
b. Polyphase sort
c. Natural merge
d. Distribution of initial runs.
232. List the hashing functions based on the methods used to find key value.
The following are the hashing functions based on the methods to find key value:
direct method, mid-square method, folding method, subtraction method, modulo-division method, pseudo-random method, digit-extraction method.
233. What are the types of collision resolution techniques and the methods used?
The following are the types of collision resolution techniques and their methods:
a. Open addressing (closed hashing) – method is overflow block
Closed addressing (Open hashing) – methods are linked list and binary tree.
234. What is a graph?
A graph is a collection of set of vertices and edges.
235. What are the types of graphs?
Directed graph and the undirected graph are the two types of graphs.
236. What is the difference between directed and undirected graph?
The difference is that in directed graph order of vertices representing edge is important whereas in undirected graph order of vertices is not important.
237. What is the other name for directed graph?
Digraph.
238. What are the commonly used representations for graphs?
The most commonly used representation of graphs are: Adjacency matrices and Adjacency lists.
239. What are the different ways of visiting all the vertices in a graph from a given vertex?
Using Depth first search and breadth first search algorithms.
240. Write the algorithm for depth first search.
Algorithm:
a. Visit a vertex and mark it as visited.
b. select an unvisited vertex w adjacent to v.
c. Repeat steps a and b till are adjacent vertices of w are visited.
d. Then go back to the last vertex visited which has an unvisited adjacent vertex and repeat step (a).
e. Stop the search when no unvisited vertex is left.
241. Write the algorithm for breadth first search.
Algorithm:
a. Visit a vertex and mark it as visited.
b. Visit all unvisited vertices adjacent to v.
c. Then visit unvisited vertices adjacent to these vertices until all the vertices are finished.
242. What is a spanning tree?
An undirected tree consisting of only those edges that are necessary to connect all the vertices in the original graph is called spanning tree of a graph.
243. What are the properties of a spanning tree?
A spanning tree has the following properties:
a. Between any pair of vertices there exists only one path.
b. Insertion of any edge to a spanning tree form a unique cycle.
244. What is depth first spanning tree?
Depth first spanning tree is the one resulting from a call to depth first tree.
245. What is breadth first spanning tree?
Breadth first spanning tree is the one resulting from a call to breadth first tree.
246. What is the use of spanning tree?
In analysis of electrical circuits, shortest route problems etc.
247. How do you determine the cost of a spanning tree?
By adding the costs of edges of that tree.
248. What is the condition to be satisfied by an edge to be included in spanning tree of Kruskal’s algorithm?
In order to be included in spanning tree of Kruskal’s algorithm, the edge should not form a cycle with already present edges.
249. What is the use of Dijkstra’s algorithm?
It is used to find shortest path between two nodes.
250. What is the type of the algorithm used in solving the 8 Queens problem?
Backtracking algorithm.
251. Does the minimum spanning tree of a graph give the shortest distance between any 2 specified nodes?
No. Minimal spanning tree assures only that the total weight of the tree is kept at its minimum. But it doesn’t mean that it provides the shortest distance between any two nodes.





































No comments: