Technical Book IPSC
Technical Book IPSC
NO
1 C & DS 1-72
1.1 Tokens 1
1.2 Operators 5
1.3 Storage Classes 9
1.4 Macro Expression 10
1.5 Decision Making Statements 13
1.6 Iterative Statements 15
1.7 Strings 19
1.8 Pointers 23
1.9 Functions 27
1.10 Arrays 29
1.11 Structures 35
1.12 Dynamic Memory Allocation 38
1.13 Files 40
1.14 Lists 44
1.15 Stacks 47
1.16 Queues 48
1.17 Trees 52
1.18 Tree Traversals 56
2 JAVA 73-84
2.1 Oops 73
2.2 Basic Introduction of java 75
2.3 Operators 75
2.4 Control Statements 76
2.5 Classes & Packages 78
2.6 Constructors 80
2.7 Threads & Collections 82
2.8 Exception Handling 83
3 DBMS 85-99
3.1 Introduction 86
3.2 Relation DBMS 86
3.3 SQL Queries 88
3.4 Joins 92
3.5 Normalization 92
3.6 Transaction Management 95
i
3.7 Hashing & Indexing 96
3.8 Deadlock & Concurrency Control 98
4 COMPUTER NETWORKS 100-104
4.1 Addressing Systems 101
4.2 LAN 101
4.3 WAN 102
4.4 Networking 102
4.5 Network Layer 103
4.6 Application Layer 104
5 OPERATING SYSTEMS 105-112
5.1 INTRODUCTION 106
5.2 Types Of Os 106
5.3 Services 107
5.4 Process 108
5.5 Process Scheduling 108
5.6 Scheduling Algorithm 109
5.7 Multithreading 110
5.8 Memory Management 110
1
C&
DATA
STRUCTURES
1
1. C Language D. Compile time error
2
A. Garbage B.dc enum
C. cd D. %d%c animals{TIGER=8,LION=7,RABBIT,ZEBRA
};
9. What will be the output? int main()
void main() {
{ enum birds m=RABBIT;
int var=10; int k=m;
printf(1+"%d",var); printf("%d\n",k);
} return 0;
A.10 B. d }
C. 10d D. D10 A. 0 B. Compilation error
C. 1 D. 1
10. Predict the Output of the Following
Program if Given Things are – 14. What will be the output of the following
void main() code?
{ void main()
int num1 = 10; {
float num2 = 20; printf("\n The number is %07d",1212);
printf("%d",sizeof(num1+num2)); }
} A. The number is 0001212
A. 2 B. 4 B. The number is 1212
C. 30 D. Garbage C. The number is 1212
D. The number is 1212000
11. Predict the Output of the Following
Program if Given Things are – 15. What is the excepted output?
#include<stdio.h> #include <stdio.h>
void main() int main()
{ {
char ch = 'ABCDEF'; printf(" "India %% India %% India "");
printf("%c",ch); getchar();
} return 0;
A. A B. ABCDEF }
C.Compile Error D. Run Time A. “India % India % India”
B. India % India % India
12. Select the right explanation to the given C. \” India %% India %% India \”
code. D. India %% India %% India
printf(“%*. *f”, 5,4,5700);
16. What is the output?[Capgemini]
A. the minimum field width has to be 4, the int main()
precision is given to be 5, and the value to be {
displayed is 5700 double x=123828749.66;
B. the minimum field width is 5, the precision int y=x;
is 4, and the value to be displayed is 5700 printf("%d\n",y);
C. compile error printf("%lf\n",y);
D. run-time error return 0;
}
13. What is the output of the following? . [Capgemini]
A. 12382874, 12382874.0
#include <stdio.h> B. 123828749, 123828749.66
enum birds{SPARROW, C. 123828749, 0.000000
PEACOCK,PARROT}; D. 0, 0.0
3
17. Predict the output of the below 22. What is the output of the following
program: program?
int main() void main()
{ {
printf("%c ", 5["HelloQuiz"]); int i = printf("00");
return 0; printf("%d",i);
} }
A. Compile-time error B. Runtime error A. 0 B. 00
C. Q D.s C. 002 D. Garbage value
18. Predict the output of the below 23. The format identifier ‘%i’ is also used
program for _____ data type?
#include<stdio.h> A.char B. int
int main() C.float D.double
{
printf("%d", printf("%d", 1234)); 24. What is the output of this C code?
return 0; int main()
} {
A.12344 B. 12341 printf("coign\r\nclass\n");
C. 11234 D. 41234 return 0;
}
19. What will be the output of the following A coignclass B.coign class
‘C’ code? C.class D.coign
main ( )
{ 25. What is the output of the following
int x = 128; Program?
printf (“n%d”, 1 + x ++); #include<stdio.h> // 32-bit compiler
} int main()
A. n128 B.n129 {
C. 130 D.131 printf("%d\t",sizeof(7.5));
printf("%d\t",sizeof(80000));
20. What will be the output of the following printf("%d",sizeof('A'));
‘C’ code? return 0;
void main() }
{ A.4 2 1 B.8 2 1
int a=0010; C.4 4 1 D.8 4 4
printf("%x",a);
} 26. A language has 28 different letters in
A.8 B.10 total. Each word in the language is
C.16 D.0 composed of
maximum 7 letters. You want to create
21. What is the output of the following a data-type to store a word of this language.
program? You decide to store the word as an array of
void main() letters. How many bits will you assign to
{ the data-type to be able to store all kinds of
int a=010; words of the language?
printf(“%o”,a); A. 7 B.35
} C.28 D.196
A.2 B. 10
C.8 D.Compile Error 27. What is output of the following
Program?
4
main() A. %, *, /, +, -
{{ B. %, +, /, *, -
unsigned int bit=256; C. +, -, %, *, /
printf(“%d”,bit); D. %, +, -, *, /
}
{unsigned int bit=512; 33. What is the output of this C code?
printf(“%d”,bit); void main()
}} {
A. 256,256 B. 512,512 int y = 3;
C. 256,512 D.Compile Error int x = 7 % 4 * y / 2;
printf("Value of x is %d", x);
28. What is the output of the following }
program? A. Value of x is 1
void main() B. Value of x is 2
{ C. Value of x is 3
printf( 3 + "goodbye"); D. value of x is 4
}
A.goodbye B.odbye 34. What is the output of this C code?
C.bye D. dbye [MAQ]
int main()
29. Which of the following statements are {
correct to print “hello world” int a = 20, b = 15, c = 5;
A. printf(“hello world” int d;
B. write(1,"hello world",11); d = a == (b + c);
C. system("echo Hello world!"); printf("%d", d);
D. All of the above }
A. 1 B. 40
30. What is the meaning of the following C. 10 D. 5
statement?
scanf("%[^\n]s", ch); 35. Assume size of an integer as 4 bytes.
A.read all character except new line What is the output of above program?
B.read all characters int main()
C. read only new line character {
D.syntax error int i = 5, j = 10, k = 15;
1.2 OPERATORS printf("%d ", sizeof(k /= i + j));
31. What is the output of this C code? printf("%d", k);
int main() return 0;
{ }
int i = 5; A. 4 1 B. 4 15
int l = i / -4; C. 2 1 D. Compile-time error
int k = i % -4;
printf("%d %d\n", l, k); 36. Which of the following statements are
return 0; correct about the program?
} int main()
A. Compile time error {
B. -1 1 unsigned int num;
C. 1 -1 int i;
D. Run time error scanf("%u", &num);
for(i=0; i<16; i++)
32. The precedence of arithmetic operators {
is (from highest to lowest)? printf("%d", (num<<i & 1<<15)?1:0);
5
} return 0;
return 0; }
} A.3 B.2
A. It prints all even bits from num C.1 D.Error
B. It prints all odd bits from num
C. It prints binary equivalent num 41. What will be the output of the program
D. Error ? [valueLabs]
void main()
37. What is the output of this C code? {
[Persistant] float a=1.1;
int main()
double b=1.2;
{
unsigned int res; if(a==b)
res = (64 >>(2+1-2)) & (~(1<<2)); printf("DOUBLE");
printf("%d\n", res); else
return 0; printf("SINGLE");
} }
A. 32 B. 64 A. SINGLE
C. 0 D. 128
B. DOUBLE
38. What will be the output of the C. Run time error
program? D. Compile time error
int main()
{ 42. What will be the value of x after
int i=4, j=8;
printf("%d, %d, %d\n", i|j&j|i, i|j&&j|i, i^j); executing these statements?[service now]
return 0; void main()
} {
A.4, 8, 0 B.1, 2, 1 int x = 10, y = 15;
C.12, 1, 12 D.0, 0, 0
x = ((x < y) ? (y + x) : (y - x);
39. What will be the output of the printf(“%d”,x);
program?
int main() }
{ A.25 B. 15
int i = 5, j = 10, k = 15;
printf("%d ", sizeof(k /= i + j)); C. 5 D. Error can't be executed.
printf("%d", k);
return 0; 43. What is the output of the following? . .
} [capgemini]
Assume size of an integer as 4 bytes. What
is the output of above program? void main()
A. 4 1 B. 4 15 {int x=5.3%2;
C. 2 1 D. Compile-time error
printf(“value of x is %d”,x);}
40. What will be the output of the program A. x=0.3 B. 2.3
?
int main() C. Compile time error
{ D. Value of x is 1
int i =(1, 2, 3);
printf("%d", i);
6
44. If(a==1||b==20) can be written as: . . D. 7,2
[Capgemini]
48. What is the output of this c code
A. If(a==1){}else if(b==2){}
#include<stdio.h>
B. If(a==1){} if(b==2){} Int main()
C. If(a==1) if(b==2){}
{
D. NONE
Int a=20,b=5,c=3;
B!=!a;
45. What is the output of c code? C=!!a;
int main()
Printf(“%d\t%d”,b,c);
{
}
int y=10000;
A. 1 1
int y=34; B. 0 3
printf(“hello world!%d\n”,y);
C. 5 1
return 0;
D. 5 3
}
A. Hello world! 1000
49. Predict output.
B. Hello world! 34
int main()
C. Hello world! Followed by a junk values
{
D. Compile time error
int a = 10, b = 20, c = 30;
if (c > b > a)
46. What is the output of the following?
printf("TRUE");
[capgemini] else
#include<stdio.h>
printf("FALSE");
int main()
return 0;
{ }
int x=2,y=0;
A. TRUE
int z=(y++)?2:y==1&&x; B. FALSE
printf(“%d\n”,z);
C. Compiler Error
return 0;
D. Output is compiler dependent
}
A.2 B.Undefined behavior
50. What will be the output of the following
C.1 D.0
code [MissionRnD]
void main()
47. What is the output of c code {
#include<stdio.h> int a=0,b=1,c=0;
int main()
int d=(++a) && (--b) &&(++c) || (--a);
{
printf("%d %d %d %d \n",a,b,c,d);
int a=1,b=2,c=3,d=4,e;
}
e=c+d=b*a;
A. 0 0 1 1 B. 1 0 1 0
printf(“%d,%d\n”,e,d); C.0 1 1 1 D. 0 0 0 0
}
A. 5,2 51. What is the output of the following code
B. Syntax error snippet?
C. 7,4
7
main() int a = 10/3;
{ printf(“%d”,a);
const int a = 5; }
a++; A. 3.33 B. 3.0
printf("%d", a); C. 3 D. 0
}
A.5 B.6 56. What would be the output:
C.Runtime error D.Compile error void main()
{
52. What is output of below code? int x = 2;
int main() int y = x << y;
{ printf(" %d\n", y);
int a@ = 10; }
printf("%d", a@); A. -2147483648 B. -1
return 0; C. Run time error D. 2
}
A. 10 57. What is the output of the following?
B. 10@ [Capgemini]
C. @ int main()
D. [Error] stray '@' in program {
int b=6;
53. Predict the output int c=7;
int main() int a=++b+c--;
{ printf("%d ",a);
char* str = "Coign"; return 0;
printf("%c\n", *&*str); }
return 0; A.13 B.Run time error
} C.14 D.16
A.Coign B.C
C.*C D.Address 58. What is sizeof() in C?
A. Operator
54. What would be the output of program? B. Function
main() C. Macro
{ D. None of these
int x = 10;
{ 59. What is the valur of K?
int x = 0; int main()
printf("%d",x); {
}} int i=3;
A. 10 B. Compilation Error int k=(i++,++i);
C. 0 D. Undefined printf("%d",k);
55. What would be the output: return 0;
void main() }
{ A. 2 B.3
8
C.5 D.4 B. Runtime Error
C. 0
1.3 STORAGE CLASSES D. 8
61. Predict the following output. 64. What will be the output of the following
int main() code?
{ int main()
int x = 5; {
int * const ptr = &x; extern int i;
++(*ptr); printf("%d ", i);
printf("%d", x); {
return 0; int i = 10;
} printf("%d ", i);
A. Compiler Error }}
B. Runtime Error A.0 10 B.Compiler Error
C. 6 C.0 0 D.10 10
D. 5
1.4 MACRO EXPRESSION
62. What will be the output of the
following? 65. What is the output of this program?
int main()
{ #include <stdio.h>
typedef int i; #define int char
i a = 7,b; main()
b=++a; {
a=b; int i=50;
printf("%d", a); printf ("sizeof (i) =%d", sizeof (i));
return 0; }
} A. 2 B. 4
A. Compiler Error C. 8 D. 1
9
66. What is the output of this program? .
[MAQ] 69. What is the output of this program?
#include <stdio.h> #define clrscr() 17
#define x 3 int main()
int main() {
{ clrscr();
int i; printf("%d\n",clrscr());
i = x*x*x; return 0;
printf("%d",i); }
return 0; A. Compilation error
} B. Runtime error
A. 27 C. 17
B. x is not declared D. none of the above
C. No output
D. Garbage value 70. What is output? [Mindtree]
#include<stdio.h>
67. What is the output of this program? 30;
#include <stdlib.h> int main()
#define square(x) x*x {
int main() printf("%d\n",30);
{ return 0;
int i; }
i = 27/square(3); A. Runtime Error
printf("%d",i); B. Garbage value
return 0; C. Compilation error
} D. 30
A. 9
B. Compilation error 71. What is the output of this program? .
C.3 [MAQ]
D. 27 #define p 17;
int main()
68. What is the output of this program? {
#include <stdio.h> printf("%d",p);
#define i 5 return 0;
int main() }
{ A. Garbage value
#define i 10 B. Runtime error
printf("%d",i); C.17
return 0; D. Compilation error
}
A. Compilation error 72. Which statment is true about the given
B. 10 code ?
C. 5 enum colors {lets,find,course};
D. Runtime error int main()
10
{
printf("%d %d %d",course,lets,find);
return 0;
}
A. 3 1 2
B. 2 0 1
C. 0 1 2
D. 1 0 2
11
The second line of output contains the
Can you solve it..?? The second line of output contains the
Task
Sample Input 0
Given set , find:
54
the maximum value of which is less than a
Sample Output 0
given integer , where and (where ) are two
Input Format
Constraints
2<=n<=10^3
2<=k<=n
Output Format
possible value of .
12
}}
A. C++
B. C
Conditional Control Statements
1.5 DECISION MAKING STATEMENTS C. Compile time error
stStatements Statements D. Run time Error
75. What is the output of the following
code? [MQA] 78. What is the output of the following
int main() program ?
{ void main (){
int x=15,y=0; int x = 2, y = 5;
if(x=10) y=7; if(x < y)
else y=1; return (x = x + y);
printf("%d",y); else
return 0; printf("%d",x);
} printf("%d",y);
A. 7 B.0 }
C.1 D.6 A. 2
B. Nothing is printed
76. Predict the output of the following . C. Segmentation fault
[persistent] D. Garbage value
void main()
{ 79. Predict the output. [zoho]
float me = 1.1; #include <stdio.h>
double you = 1.1; #define PRINT(i, limit) do
if(me==you) { if (i++ < limit)
printf("I love India"); { printf("GeeksQuizn");
else continue;
printf("I am Indian"); } }while(0)
} int main()
A. I love India {
B. I am Indian int i = 0;
C. 1.1 PRINT(i, 3);
D. Compile time Error return 0;
}
77. What will be output of the following How many times GeeksQuiz is printed in the
program? [TCS] above program ?
#include<stdio.h> A. 1
void main() B. 3
{ C. 4
float a=0.7; D. Compile-time error
if(a<0.7){
printf("C"); 80. What is the output of the following
} else code? [Neso]
{ printf("C++"); void main()
13
{ int i=-5; if(i=0,2,3)
while(i<=5) printf("Indian ");
{if(i>=0) else
break; printf("Citizen");
else{ printf("%d\n",i);
i++; continue; } }
printf(“Neso”); A. Citizen 3
}} B. Citizen 0
A.10 times Neso B.5 times C. Indian 0
C. Infinite times D.0 times D. Indian 3
81. Output of the following? [Neso] 84. Predict the output of the following
#include <stdio.h> int main()
void main() {
{int i=0; if(!printf(""))
for(printf("one\n");i<3&&printf("");i++) printf("hi");
{ }
printf("Hi\n"); A. hi
}} B. Nothing is printed
A. Hi Hi Hi C. Space is printed
B. One D. Compile time error
C. One Hi One Hi One Hi
D. One One One 85. Predict the output. [TCS]
int i;
82. What will be the output of the int main()
following. [capgemini] {
void main() if(i)
{ printf("hello");
int x=0; else
if(x=0) printf("hi");
printf("its zero"); }
else A. hi
printf("its not zero"); B. hello
} C. compile time error
A. Its zero D. garbage value
B. Its not zero
C. Error 86. What will be the output of the calling
D. Garbage value void main()
{
83. Predict the output of the following if (printf("hi") != 5)
#include"stdio.h" printf("welcome");
int main() else
{ printf("morning");
int i; }
14
A.hiwelcome B.welcome C. 4 only.
C.morning D.welcomehi D. 2,3 and 4.
87. What will be the output of the 90. What will be the output of following
following? [GGK] program ?
#include<stdio.h> #include <stdio.h>
int main(){ int main()
unsigned int x= -1; {
int y=~0; if( (-100 && 100)||(20 && -20) )
if(x==y) printf("%s","Condition is true.");
printf("same"); else
else printf("%s","Condition is false.");
printf("not same"); return 0;
return 0; }
} A. Condition is true.
A. not same B. Condition is false.
B. same C. No output
C. 0 D. ERROR
D. none
1.6 ITERATIVE STATEMENTS
88. What will be the output of following
program ? 91. Consider the following C program
#include <stdio.h> . [MindTree]
void main() main()
{ {
int x=22; float sum = 0.0, j =1.0, i = 2.0;
if(x=10) while(i/j > 0.001) {
printf("TRUE"); j = j + 1;
else sum = sum + i/j;
printf("FALSE"); printf ( "%fn", sum );
} }}
A. TRUE How many lines of output does this program
B. FALSE produce?
C. Error A. 0-9 lines of output
D. None B. 10-19 lines of output
C. 20-29 lines of output
89. Which of the following are incorrect D. More than 29 lines of output
statements? If int a=10.
1) if( a==10 ) printf("IncludeHelp"); 92. Predict the output of the following. .
2) if( 10==a ) printf("IncludeHelp"); [persistent]
3) if( a=10 ) printf("IncludeHelp"); Void main()
4) if( 10=a ) printf("IncludeHelp"); {
A. 3 and 4. for (a=1;a<=100;a++)
B. 3 only. for(b=a;b<=100;b++)
15
foo(); void main()
} {
foo() int check=3;
{} switch(check){
how many times foo will be called? case 1: printf("D.W.Steyn");
A. 5050 B.1010 case 2: printf(" M.G.Johnson");
C.1111 D.1001 case 3: printf(" Mohammad Asif");
default: printf(" M.Muralidaran");
93. What will be output of following c }}
code? [zoho] A. Mohammad Asif
#include<stdio.h> B. M.Muralidaran
extern int x; C. C.D.W.Steyn M.G.Johnson Mohammad
int main() Asif M.Muralidaran
{ D. D.Mohammad Asif M.Muralidaran
int x=8;
do{ 96. What will be output when you will
do{ execute following c code?
printf("%o",x); #include<stdio.h>
} while(!-2); void main()
}while(0); {
return 0; int movie=1;
} switch(movie<<2+movie){
A. Compile time error default:printf("3 Idiots");
B. Run time error case 4: printf(" Ghajini");
C. 10 case 5: printf(" Krrish");
D. 8 case 8: printf(" Race");
}}
94. What will be output of following c A. 3 Idiots Ghajini Krrish Race
code? B. Race
#include<stdio.h> C. Krrish
int main() D. Ghajini Krrish Race
{
int i=2,j=2; 97. What will be output if you will execute
while(i+1?--i:j++) following c code?
printf("%d",i); #include<stdio.h>
return 0; void main()
} {
A. 1 int i;
B. 2 for(i=0;i<5;i++){
C. Error int i=10;
D. Compile time error printf(" %d",i);
i++;
95. What will be output when you will }}
execute following c code? [zoho] A. 10 11 12 13 14
16
B. 10 10 10 10 10 Printf(“yes\n”);
C. 0 1 2 3 4 Case max(1);
D. Compilation error Printf(“no\n”);
Break;
98. Predict the output of the following. }}
#include<stdio.h> A. Yes
void main() B. Compile time error
{ C. No
int x=0,y=1,j; D. Yes no
for(j=1;j<4;j++)
{ 101. What is the output of this c code? .
x=x+j; [capgemini]
y*=j;
}printf("x=%d \t y=%d\n",x,y); #include<stdio.h>
} int main()
A. x=6 y=6 {
B. x=5 y=6 int i=0;
C. x=6 y=4 while(i<2)
D. x=4 y=5 {
if(i==1)
99. Predict the following output of the break;
program. [Neso] i++;
int main() if(i==1)
{ continue;
unsigned int i=500; printf("in while loop\n");
while(i++!=0); }printf("after loop\n");
printf("%d",i); }
return 0; A. In while loop
} B. In while loop after loop
A. 1 C. after loop
B. Infinite loop D. in while loop in while loop after loop
C. Program will crush
D. 501 102. Predict the output of the following.
[capgemini]
100. What is the output of this c code. . int main()
[Capgemini] {
#include<stdio.h> int i=0;
#define max(a)a char c='a';
Int main() while(i<2){
{ i++;
Int x=1; switch(c){
Switch(x); case 'a':
{ printf("%c",c);
Case max(2); break;
17
break; } }
}printf("after loop\n"); A. 1,2,3
} B. 4,2
A. None of the mentioned C. 1,2,5
B. after loop D. 1,2
C. a after loop
D. a a afterloop 106. what is the output of this program
main()
103. what is the output of this program {
int i=10; int cnt=5, a=100;
while(1) do{
i++; a/=cnt;
printf("%d",i); }while(cnt--);
A. 11 printf("%d\n",a);
B. 10 }
C. compile error A. 100
D. infinite loop B. 20
C. compilation error
104. what is the output of this program. D. runtime error
#include<stdio.h>
main() 107. what is the output of this program
{ int main()
int i=20, k=0,j; {
for(j=1;j<i+4*(i/j);j++) int i=1024;
{ for(;i;i>>=1)
k+=j<10?4:3; printf("hello,world");
} return 0;
printf("%d ",k); }
} A. 10
A. 20 B. 11
B. 69 C. Infinite
C. 14 D. Compile time error
D. Compile time error
108. What will be the output of the following
105. what is the output of this program. code?
main() #include<stdio.h>
{ int main()
int i=0, j=0, sum=1; {
while(sum<4){ int n;
printf("%d ",sum); for (n = 9; n!=0; n--)
i=j; printf("n = %d", n--);
j=++sum; return 0;
sum= i+j; }
} A. 9 7 5 3 1
18
B. 987654321 {
C. Infinite Loop unsigned int i = 65000;
D. 9753 while (i++ != 0);
printf("%d", i);
109. Predict the output. return 0;
int main() }
{ A. Infinite Loop
while(1){ B. 0
} C. 1
return 0; D. Run Time Error
} .
A. 1 112. What will be the output of the following
B. Runtime Error C code?
C. 0 main( )
D. Infinite loop {
int i;
110. What’s going to happen when we for ( i=0; i<5; i++ )
compile and run the following C program {
#include<stdio.h> int i = 10;
int main() printf ( "%d ", i );
{ i++;
int i = 1, j; }
for ( ; ; ) return 0;
{ }
if (i) A. 10 11 12 13 14
j = --i; B. 10 10 10 10 10
if (j < 10) C. 0 1 2 3 4
printf("Hello ", j++); D. Compilation error
else
break; 1.7 STRINGS
}
113. If the two strings are identical, then
return 0; strcmp() function returns.
}
A. Compile Error. A. -1
B. No compile error but it will run into B. 1
C. 0
infinite loop printing Hello.
D. Ye
C. No compile error and it’ll print Hello10
times. 114. What is the output of the following. .
D. No compile error but it’ll print Hello 9 [capgemini]
times int main()
{
char *a={"p","r","o","g","r","a","m"};
111. Predict the output.
printf("%s",a);
#include <stdio.h> return 0;
int main() }
19
A. p char str1[20] = "Hello", str2[20] = " World";
B. No output printf("%s", strcpy(str2, strcat(str1, str2)));
C. Compile time error return 0;
D. Program }
A.Hello B.World
115. What is the output of the following C.Hello World D.WorldHello
code. [capgemini]
int main() 118. What will be the output of the program
{ ?
char *str="good morning"; #include<stdio.h>
char *str1="good morning"; #include<string.h>
if(strcmp(str,str1)) int main()
printf("equal"); {
else printf("%d", strlen("123456"));
printf("unequal"); return 0;
} }
A. equal A. 6 B.12
B. unequal C.7 D.2
C. compile time error
D. depends on compiler 119. What will be the output of the program
?
116. Which of the following statements are int main()
correct about the program below? {
int main() char str[] = "AstiwzQUIZ";
{ printf("%s", str);
char str[20], *s; return 0;
printf("Enter a string\n"); }
scanf("%s", str); A. QUIZ
s=str; B. Astiwz
while(*s != '\0') C. Astiwz QUIZ
{ D. AstiwzQUIZ
if(*s >= 97 && *s <= 122)
*s = *s-32;
s++; 120. What is the output of following
} program?
printf("%s",str);
return 0; int main()
} {
A. The code converts a string in to an integer char str1[] = "Ccompiler";
B. The code converts lower case character to
char str2[] = {'C', 'c', 'o', 'm', 'p', 'i', 'l', 'e', 'r'};
upper case
C. The code converts upper case character to int n1 = sizeof(str1)/sizeof(str1[0]);
lower case int n2 = sizeof(str2)/sizeof(str2[0]);
D. Error in code printf("n1 = %d, n2 = %d", n1, n2);
return 0; }
117. What will be the output of the program A. n1=10, n2=9
? B. n1= 10, n2=10
#include<stdio.h> C. n1=9 , n2=9
#include<string.h> D. n1=9, n2=10
int main()
{
20
121. Consider the following C program char s[ ]="man";
segment: int i;
void main() for(i=0;s[i];i++)
{ printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
char p[20]; }
char *s = "string"; A. Mmmmaaaannnn
int length = strlen(s); B. Mmmaaannn
int i; C. Error
for (i = 0; i < length; i++) D. Man
p[i] = s[length — i];
printf("%s", p); 126. Consider the following C program
} segment.
A.gnirts B.gnirt void main()
C.string D.no output is printed {
char string[]="Hello World";
122. What does the following fragment of C- display(string);
program print? }
char c[] = "GATE2011";
void display(char *string)
char *p =c;
printf("%s", p + p[3] - p[1]) ; {
A.GATE2011 B.E2011 printf("%s",string);
C.2011 D.011 }
A.Hello World B.Erroe
123. Assume that a character takes 1 byte. C.World D.Hello
Output of following program?
#include<stdio.h> 127. What will be output when you will
int main()
execute following c code? [zoho]
{
char str[20] = "HelloQuiz"; void main()
printf ("%d", sizeof(str)); {
return 0;} char arr[11]="The African Queen";
A.9 B.10 printf("%s",arr);
C.20 D.Garbage value }
A. The African Queen
124. Consider the following C program
B. the
segment.
# include <stdio.h> C. The African
int main( ) D. Compilation Error
{
char s1[7] = "1234", *p; 128. What is the output of this C code?
p = s1 + 2; #include<stdio.h>
*p = '0' ;
void main()
printf ("%s", s1);
} {char *str=””;
A.12 B.120400 do{
C.1204 D.1034 printf(“hello”);
}while(str);
125. What is the output of following }
program? [Persistant] A. Nothing
void main(){ B. Run time error
21
C. Hello 132. What is the output of this C code?
D. Hello is printed infinite times int main()
{
129. What is the output of this C code? char str[] = "Code\0Quiz\0";
[ValueLabs] printf("%s\n", str);
main() return 0;
{ }
char str[10]={'0','1','0','0','0','0','0','0','0','0'}; A.Quiz B.Code
char *s; C.Code Quiz D.Code\0Quiz
s=str;
for(int i=0;i<=9;i++) 133. Predict the output?
{ int fun(char *str1)
if(*s-48) {
printf("%c",*s); char *str2 = str1;
s++; while(*++str1);
}} return (str1-str2);
A.1 B.0 1 0 0 0 0 0 0 0 0 }
C.Errro D.0 int main()
{
130. What is the output of this C code? . char *str = "GeeksQuiz";
[cocudes] printf("%d", fun(str));
int main() return 0;
{ }
char str[25] = "welcome"; A.10 B.9
printf("%s\n", str+2); C.8 D.Random number
return 0;
} 134. Predict the output of the following
A. lcome B.welcome program:
C.wel D.error #include <stdio.h>
int main()
131. What is the output of this C code? {
int main() char str[] = "%d %c", arr[] = "Helloworld”;
{ printf(str, 0[arr], 2[arr + 3]);
int i; return 0;
char a[] = "\0"; }
if(printf("%s", a)) A. H w B.72 81
printf("empty string\n"); C.72 w D.Compile time error
else
printf("not empty string \n"); 135. What will be the output of the program
return 0; ?
} #include<stdio.h>
A.empty string B.Not empty string int main()
C.No output D.0 {
22
char *names[] = { "Suresh", "Siva", "Sona", 138. Predict the output of the following?
"Baiju", "Ritu"}; [persistent]
int i; void main()
char *t; {
t = names[3]; int const * p=5;
names[3] = names[4]; printf("%d",++(*p));
names[4] = t; }
for(i=0; i<=4; i++) A.6 B.5
printf("%s,", names[i]); C.Garbage value D.Compiler error
return 0;
} 139. What will be the output of the following
A. Suresh, Siva, Sona, Baiju, Ritu c code? [persistent]
B. Suresh, Siva, Sona, Ritu, Baiju main()
C. Suresh, Siva, Baiju, Sona, Ritu {
D. Suresh, Siva, Ritu, Sona, Baiju int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
1.8 POINTERS for(j=0;j<5;j++) {
printf(" %d ",*c);
136. Predict the output of the following? . ++q; }
[capgemini] for(j=0;j<5;j++){
#include <stdio.h> printf(" %d ",*p);
int main() ++p; }
{ }
int k=5,*p=&k; A. 2 2 2 2 2 2 3 4 6 5
int **m=&p; B. 2 8 3 4 4 6 7 5
printf("%d%d%d\n",k,*p,**m); C. 5
return 0; D. Compiler error
}
A.555 B.Run time error 140. Predict the output of the following.
C.5 junk junk` D.5 5 junk value [persistent]
main()
137. What will be the output of the {
following. [Capgemini] char *p; //32-bit complier
int main() printf("%d %d ",sizeof(*p),sizeof(p));
{ }
int x=4; A.1 4 B.1 8
int *p=&x; C.Syntax error D.Compile time error
int *k=p++;
int r=p-k; 141. Consider the code and select an option
printf("%d",r); below? [persistent]
} main()
A.1 B.2 {
C.4 D.8 char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
23
p=&s[3]; {
str=p; int i=0,j=1;
str1=s; int *a[]={&i,&j};
printf("%d",++*p + ++*str1-32); printf("%d",(*a)[1]);
} return 0;
A.a B.65 }
C.77 D.97 A.1 B.0
C.0 1 D.1 0
142. What will be output of following
program? [zoho] 145. What substitution should be made to //-
#include<stdio.h> ref such that ptr1 points to variable c
int main() #include<stdio.h> [Capgemini]
{ Int main()
int a = 320; {
char *ptr; int a=1,b=2,c=3;
ptr =( char *)&a; int *ptr1=&a;
printf("%d ",*ptr); int **sptr=&ptr1; //-ref
return 0; }
} A. None of the mentioned
A.2 B.320 B. *ptr1=&c;
C. 64 D.Compilation Error C. *sptr=&c;
D. **sptr=&c;
143. Predict the output of the following.
[Zoho] 146. What is the output of the following
#include<conio.h> code? [Capgemini]
int main() void main()
{ {
void (*p)(); int ary[2][3];
int (*q)(); foo(ary);
int (*r)(); }
p = clrscr; void foo(int *ary[])
q = getch; {
r = puts; int i=10,j=2,k;
(*p)(); ary[0]=&i;
(*r)("hello"); ary[1]=&j;
(*q)(); *ary[0]=2;
return 0; for(k=0;k<2;k++)
} printf("%d\n",*ary[k]);
A.NULL B.hello }
C.h D.Compilation Error A.2 2 B.10 2
C.1 1 D. Error
144. Predict the output of the following?
[Capgemini] 147. Consider the code below? .
int main() [Capgemini]
24
#include<stdio.h> 150. What is the output of this c code. .
int main() [Capgemini]
{ #include<stdio.h>
int i=97, *p=&i; #include<stdio.h>
go(&i); int *f();
printf("%d",*p); int main()
} {
void go(int *p) int *p=f();
{ printf("%d\n",*p);
int j=2; }
p=&j; int *f()
printf("%d ",*p); {
} int *j=(int*)malloc(sizeof(int));
A. 2 97 *j=10;
B. 2 2 return j;
C. Code crash\segmentation fault }
D. Compile time error A. Segmentation fault/runtime crash since
pointer to local variable is returned
148. What is the output of the following? . B. 10;
[TCS] C. Compile time error
#include<stdio.h> D. Undefined behavior
int main()
{
void *p;
int a[4]={1,2,3,8};
p=&a[3];
int *ptr= &a[2];
int n=p - ptr;
printf("%d\n",n);
}
A.Compile time error B.1
C.4 D.Segmentation fault
25
Constraints:
1<= total number of words in the text <=
30,000
1<= length of alpha and beta words <= 500
Can you solve it..??
1<=K<=total number of alpha words
1<=lb<=ub<=total number of beta words
Task:
Sample Input and Output
Consider text comprised of sentences and
sentences comprised of words. Words in a
sentence will be space delimited. Text will SNo. Input Output
comprise of two types of words, viz. alpha words
and beta words. Alpha words are denoted in the
input. All words in the text which are non-alpha The European market crashes
words are beta words. Task is to find out the on Mondays. Crashes in the
number of valid segment with number of beta European market are quite
words in the given range [lb, ub]. common.
234
A segment is said to be valid if European
- It contains all the K-strings 1 Crashes 1
- It should start and end with any one of the K-
strings
Explanation:
Input Format:
Valid segments are:
First line contains the text. Next line contains K,
European market crashes
lb, ub. Next K lines consist of alpha words in the
crashes on Mondays. Crashes in the European
text.
Crashes in the European
Note:
There is only one valid segment with number of
1. String comparison should be case insensitive.
beta words in the range [3, 4], which is segment
2. String comparison should be based only on
2.
words comprised of alphabets. Non-alphabet
characters such as Full Stop ("."), Exclamation
Marks ("!") etc. are called as Stop words. Stop
words must be removed from sentences before
comparison.
3. If more than one segment starts with the same
index (i.e. position of the word in the text), then
consider the shortest segment. In other words,
segments should begin from unique indexes.
Output Format:
Print the number of valid segments with number
of beta words in the given range [lb, ub].
26
Functions #include<stdio.h>
main()
1.9 FUNCTIONS {
static int var = 5;
151. foo() call how many times. [persistent]
for(i=1;i< =100;i++) printf("%d ",var--);
for (j=1;j<=100;j++) if(var)
foo(); main();
A.5050 B.5040 }
A.4 3 2 1 B.5 4 3 2 1
C.4040 D.Error
C.3 2 1 D.1
152. Predict the output. [persistent]
func(char *s1,char * s2) 155. Find the output of below program.
#include <stdio.h>
{
char *t; int main()
t=s1; {
s1=s2; void demo();
s2=t; void (*fun)();
} fun = demo;
void main() (*fun)();
{ fun();return 0;
}
char *s1=”jack”, *s2=”jill”;
func(s1,s2); void demo()
printf(“%s %s ”,s1,s2); {
printf("GoodDay");
}
A.jack jill B.jill }
C.error D.1 A. GoodDay
B. GoodDay GoodDay
C. Compiler Error
153. Predict the output.
D. Blank Screen
void main()
{
int n,i; 156. What is the meaning of using extern
printf("enter any no"); before function declaration? For example
scanf("%d",&n); following function sum is made extern
for(i=0;i<n;i++) extern int sum(int x, int y, int z)
{ {
printf(" %d",fib(i)); return (x + y + z);
}} }
Find the output of above program for n=8. A. Function is made globally available
A. 0 1 1 2 3 5 8 B. extern means nothing, sum() is same
B. 0 1 1 2 3 5 8 13 without extern keyword.
C. 0 1 1 2 3 5 8 8 8 8 C. Function need not to be declared before its
use
D. Error
D. Function is made local to the file.
154. Predict the following. [persistent]
27
157. The value of j at the end of the A. Garbage value
execution of the following C program. B. 0 (Zero)
int incr(int i) C. 1990
{ D. No output
static int count = 0;
count = count + i; 160. What will be the output of the
return (count); program?
} #include<stdio.h>
main() int i;
{ int fun();
int i,j; int main()
for (i = 0; i <=4; i++) { while(i)
j = incr(i); { fun();
} main();
A.10 B.4 } printf("Hello\n");
C.6 D.7 return 0;
}
158. Consider the following C function: . int fun()
[ISRO] {
int f(int n) printf("Hi");
{ }
static int i = 1; A. Hello
if(n >= 5) return n; B. Hi Hello
n = n+i; C. No output
i++; D. Infinite loop
return f(n);
} 161. The output of the code below is
The value returned by f(1) is #include <stdio.h>
A.5 B.6 int *n()
{
C.7 D.8
int *p = 5;
return p;
159. Predict the output. [IBM] }
int main() void main()
{ {
int fun(); int *k = n();
int i; printf("%d", k);
}
i = fun();
A. 5 B. Junk value
printf("%d\n", i); C. 0 D. Error
return 0;
}
int fun() 162. What is the output of this C code?
{ #include <stdio.h>
void m(int *x, int *y)
int x= 1990;
{
} int temp = *x; *x = *y; *y = temp;
28
} printf("%d ", arr[i]);
void main() }
{ int main()
int a = 6, b = 5;
{
m(&a, &b);
printf("%d %d\n", a, b); int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};
} print(arr);
A. 5 6 B. 6 5 return 0;
C. 5 5 D. 6 6 }
A. 1, 2, 3, 4, 5, 6, 7, 8
163. What is the output of this C code? B. Compiler Error
#include <stdio.h>
C. 1 2
void m(int *p)
{ D. Run Time Error
int a = 0;
for(a = 0;a < 5; a++) 166. Does C perform array out of bound
printf("%d\t", p[a]); checking? What is the output of the
} following program?
void main() int main()
{
{
int i[5] = {6, 5, 3};
m(&i); int i;
} int arr[5] = {0};
A. 0 0 0 0 0 B. 6 5 3 0 0 for (i = 0; i <= 5; i++)
C. Run time error D. 6 5 3 junk junk printf("%d ", arr[i]);
return 0;
1.10 ARRAYS }
A. Compiler Error: Array index out of bound.
164. Predict output of following program. B. The always prints 0 five times followed by
int main()
garbage value
{ C. The program always crashes.
int i;
D. The program may print 0 five times
int arr[5] = {1};
followed by garbage value, or may crash if
for (i = 0; i < 5; i++) address (arr+5) is invalid.
printf("%d ", arr[i]);
return 0;
167. Pick the best statement for the below:
}
int arr[50] = {0,1,2,[47]=47,48,49};
A. 1 followed by four garbage values
A. This isn’t allowed in C and it’ll give
B. 1 0 0 0 0 compile error
C. 1 1 1 1 1
B. This is allowed in C as per standard.
D. 0 0 0 0 0
Basically, it’ll initialize arr[0], arr[1], arr[2],
arr[47], arr[48] and arr[49] to 0,1,2,47,48 and
165. What is output? 49 respectively. The remaining elements of the
void print(int arr[]) array would be initialized to 0.
{
int n = sizeof(arr)/sizeof(arr[0]);
168. Pick the best statement for the below
int i;
program:
for (i = 0; i < n; i++)
29
int size = 4; static int arr[] = {0, 1, 2, 3, 4};
int arr[size]; int *p[] = {arr, arr+1, arr+2, arr+3, arr+4};
int main() int **ptr=p;
{ ptr++;
if(arr[0]) printf("%d, %d, %d\n", ptr-p, *ptr-arr,
printf("Initialized to ZERO"); **ptr);
else *ptr++;
printf("Not initialized to ZERO"); printf("%d, %d, %d\n", ptr-p, *ptr-arr,
return 0; **ptr);
} *++ptr;
A. No compile error and it’ll print “Initialized printf("%d, %d, %d\n", ptr-p, *ptr-arr,
to ZERO”. **ptr);
B. No compile error and it’ll print “Not ++*ptr;
initialized to ZERO”. printf("%d, %d, %d\n", ptr-p, *ptr-arr,
C. Compile error because size of arr has been **ptr);
defined using variable outside any function. return 0;
D. No compile error and it’ll print either }
“Initialized to ZERO” or “Not initialized to A.0, 0, 0 B.1 1 2
ZERO” depending on what value is present at 1, 1, 1 223
arr[0] at a particular run of the program. 2, 2, 2 334
3, 3, 3 441
169. What will be the output of the C. 1, 1, 1 D. 0 1 2
program? 2, 2, 2 123
void fun(int **p); 3, 3, 3 234
int main() 3, 4, 4 345
{
int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0}; 171. What will be the output of the program
int *ptr; in Turbo C (under DOS)?
ptr = &a[0][0]; int main()
fun(&ptr); {
return 0; int arr[5], i=0;
} while(i<5)
void fun(int **p) arr[i]=++i;
{
printf("%d\n", **p); for(i=0; i<5; i++)
} printf("%d, ", arr[i]);
A. 1 B.2 return 0;
C. 3 D.4 }
A. 1, 2, 3, 4, 5,
170. What will be the output of the B. Garbage value, 1, 2, 3, 4,
program? C. 0, 1, 2, 3, 4,
#include<stdio.h> D. 2, 3, 4, 5, 6,
int main()
{
30
172. Which of the following concepts make II. x+1
extensive use of arrays? III. x++
A. Binary trees IV. x*2
B. Scheduling of processes A. I and II
C. Caching B.I, II and III
D. Spatial locality C.II and III
D. I, III and IV
173. In C Programming, If we need to store
word “INDIA” then syntax is as below – 177. What will be the output of the
char name[]; program?
name = “INDIA” int main()
A. char name[6] = {'I','N','D','I','A'}; {
B. char name[6] = {'I','N','D','I','A','\0'} int a[3] = {10,12,14},i=0;`
C. char name[6] = {"I","N","D","I","A"} a[1]=30;
D. name = "INDIA" while(i<3)
{
174. What will be printed after execution of printf("%d ", i[a]);
the following code? i++;
void main() }}
{ A. 30 12 10 B. 10 10 10
int arr[10] = {1,2,3,4,5}; C. 10 30 14 D. None of the above
printf("%d", arr[5]);
} 178. What is the output of C program?
A.Garbage Value B.5 int main()
C.6 D.0
{
175. What will be printed after execution of float marks[3] = {90.5, 92.5, 96.5};
the following code? int a=0;
int main() while(a<3){
{ printf("%.2f,", marks[a]);
int a[5] = {51, 1, 5, 20, 25}; a++;
int x, y, z; } }
x = ++a[1]; A. 90.5 92.5 96.5
y = a[1]++; B. 90.50 92.50 96.50
z = a[x++]; C. 0.00 0.00 0.00
printf("%d, %d, %d", x, y, z); D. Compiler error
return 0;
} 179. What is the output of C program?
A.2, 3, 20 B.2, 1, 5 int main()
C.1, 2, 5 D.3, 2, 5
{
int a[3] = {20,30,40};
176. Let x be an array. Which of the
a[0]++;
following operations are illegal?
int i=0;
I. ++x
while(i<3)
31
{ printf("%d",*(*(*(ary+1)+ 1)+2));
printf("%d ", i[a]); return 0;
i++; }
}} A. 10 B. 11
A. 20 30 40 B. 41 30 20 C. 12 D. Compiler error
C. 21 30 40 D. None of the above
183. An array elements are always stored in
180. What is the output of C Program with ______
A.Sequential B.Random
arrays and pointers?
C.Hierarchal D.Unarranged
void change(int[]);
int main() 184. Which of the following is right way to
{ access 7th element in an array.
int a[3] = {20,30,40}; A. Arr[6]
change(a); B. Arr[7]
printf("%d %d", *a, a[0]); C. Arr[8]
D. Arr{6}
}
void change(int a[]) 185. Int a[6]={0}, what are the values of
{ array if the array is printed.
a[0] = 10;
} A.1 1 1 1 1 1 B.0 0 0 0 0 1
C.1 0 0 0 0 0 D.0 0 0 0 0 0
A. 20 20 B. 10 20
C. 10 10 D. 20 30 186. Predict the output of below program: .
[capgemini]
181. What is the output of C Program with int main()
arrays and pointers? {
int main() int arr[4]={1,2,3,4};
{ int *p=arr+3;
printf("%d %d\n",p[-2],arr[*p]);
int ary[] = {11, 33, 55};
return 0;
int *p, *q; }
p = ary; A. 2 4
q = ary+2; B. Compile time error
printf("%d %d",*p, *q); C. 2 Garbage value (or) 2 0
return 0; D. 2 3 (or) 0 0
}
187. In C, if you pass an array as an
A. 0 35 B. 11 33
argument to a function, what actually gets
C. 11 55 D. Compiler error. passed?
A. Value of elements in array
182. What is the output of C Program? B. First element of the array
int main() C. Base address of the array
{ D. Address of the last element of array
int ary[2][2][3] = {
188. What is the maximun number of
{{1,2,3},{4,5,6}}, dimensions an array in C may have?
{{7,8,9},{10,11,12}} A. two
}; B. eight
32
C. twenty A. 1
D. Theoretically no limit. The only practical B. 2
limits are memory size and compiler C. Compile time error
D. Some garbage value
189. Choose the correct statements
A. an entire array can be passed as an 193. The C declaration int A[5][7]
argument to a function Contains x elements, each of these elements is
B. a part of an array can be passed as argument itself an array containing y
to a function
integers. What is the value of 2x+y
C. any change done to an array that is passed as
an argument to a function will be local to the A. 17
function B. 20
D. Both (a) & (b) C. 12
D. 34
190. What will be the output of the program
in Turbo-C?
int main(){
int arr[5], i=-1, z;
Can you solve it..??
while(i<5)
arr[i]=++i;
for(i=0; i<5; i++) Task
printf("%d, ", arr[i]); Given an integer n, generate a square
return 0; matrix filled with elements from 1 to n2 in
} spiral order.
A. 1, 2, 3, 4, 5,
B. -1, 0, 1, 2, 3, 4 Sample Input:
C. 0, 1, 2, 3, 4,
D. 0, -1, -2, -3, -4 Given n = 3,
33
Structures
D. Error
34
int y; };
}; int main(){
void foo(struct point *); struct employee emp[] ={ {1,"Mike",24},
void main() {2,"AAA",24},
{ {3,"BBB",25},
struct point p1[]={1,2,3,4}; {4,"CCC",30}};
foo(p1); printf("Id : %d, Age : %d, Name: %s",
} emp[2].empid,3[emp].age,(*(emp+1)).name);
void foo(struct point p[]) return 0;
{ }
printf("%d %d\n",p->x,++p->x); A. Id: 3, Age : 24, Name : Mike
} B. Id: 3, Age : 23, Name : Mike
A.1 2 B.Undefined behavior C. Id: 3, Age : 30, Name : AAA
C.2 2 D.Compile time error D. ERROR
199. What is the output of this c code 201. Predict the following output.
.[Capgemini] #include<stdio.h>
#include<stdio.h> struct p
struct point {
{ struct p *next;
int x; int x;
int y; };
}; int main()
struct notpoint {
{ struct p *p1=calloc(1,sizeof(struct p));
int x; p1->x=1;
int y; p1->next=calloc(1,sizeof(struct p));
}; printf("%d\n",p1->next->x);
int main() return 0;
{ }
struct point p={1}; A.1 B.Garbage value
struct notpoint p1; C.0 D.Error
p1=p;
printf("%d\n",p1.x); 202. What will be the output of the
} following. [Capgemini]
A.Compile time error B.O #include<stdio.h>
C.Undefined D.1 union u{
struct p
200. Predict the output of the following {
#include <stdio.h> unsigned char x:2;
struct employee{ unsigned int y:2;
int empid; }p;
char *name; int x;
int age; };
35
int main() A. Compile time error
{ union u u; B. 10 10
u.p.x=2; C. Depends on the standard
printf("%d\n",u.p.x); D. Depends on the compiler
}
A. 2 205. Predict the output of the following.
B. Compile time error #include <stdio.h>
C. 0 struct p
D. Run time error {
int k;
203. What will be the output of the char c;
following. float f;
#include <stdio.h> };
struct student int p = 10;
{ int main()
char *name; {
}; struct p x = {1, 97};
void main() printf("%f %d\n", x.f, p);
{ }
struct student s, m; A. Compile time error
s.name = "st"; B. 10
m = s; C. Somegarbage value 10
printf("%s%s", s.name, m.name); D. 0 10
}
A. Compile time error 206. Assume that objects of the type short,
B. Nothing float and long occupy 2 bytes, 4 bytes and 8
C. Junk values bytes, respectively. The memory
D. st st requirement for variable t, ignoring
alignment considerations, is (GATE CS
204. What will be the output of the following 2000)
C code? A.22 bytes B.14 bytes
#include <stdio.h> C.18 bytes D.10 bytes
struct p
{ 207. Predict the output.
int k; union test
char c; {
}; int x;
int p = 10; char arr[8];
int main() int y;
{ };
struct p x; int main()
x.k = 10; {
printf("%d %d\n", x.k, p); printf("%d", sizeof(union test));
} return 0;
36
} int y;
Predict the output of above program. Assume };
that the size of an integer is 4 bytes and size of int main()
character is 1 byte. Also assume that there is no {
alignment needed. union test t;
A.12 B.16 t.x = 0;
C.8 D.Compiler Error t.arr[1] = 'G';
printf("%s", t.arr);
208. Pick the best statement for the below return 0;
program: }
#include "stdio.h" Predict the output of above program. Assume
int main() that the size of an integer is 4 bytes and size of
{ character is 1 byte. Also assume that there is no
union {int i1; int i2;} myVar = {.i2 =100}; alignment needed.
printf("%d %d",myVar.i1, myVar.i2); A. Nothing is printed
return 0; B. G
} C. Garbage character followed by 'G'
A. Compile error due to incorrect syntax of D. Garbage character followed by 'G',
initialization. followed by more garbage characters
B. No compile error and it’ll print “0 100”.
C. No compile error and it’ll print “100 100”. 1.12 DYNAMIC MEMORY ALLOCATION
D. None
211. What is the output of the following code
209. Consider the following C declaration. if the input entered as first and second
[GATE] number is 5 and 6 respectively?
struct ( #include<stdio.h>
short s[5]; #include<stdlib.h>
union { main()
float y; {
long z; int *p;
}u; p=(int*)calloc(3*sizeof(int));
}t; printf("Enter first number\n");
Assume that the objects of the type short, float scanf("%d",p);
and long occupy 2 bytes, 4 bytes and 8 bytes, printf("Enter second number\n");
respectively. The memory requirement for scanf("%d",p+2);
variable t, ignoring alignment consideration, is printf("%d%d",*p,*(p+2));
A.22 bytes B.18 bytes free(p);
C.14 bytes D.10 bytes }
A. 56
210. What is the output of the following? B. Address of the locations where the two
union test numbers are stored
{ C. 57
int x; D. Error
char arr[4];
37
212. A condition where in memory is 215. What is the problem with following
reserved dynamically but not accessible to code?
any of the programs is called _____________ #include<stdio.h>
A. Memory leak int main()
B. Dangling pointer {
C. Frozen memory int *p = (int *)malloc(sizeof(int));
D. Pointer leak p = NULL;
free(p);
213. What is the output of the following }
code? A. Compiler Error: free can't be applied on
#include<stdio.h> NULL pointer
#include<stdlib.h> B. Memory Leak
void main() C. Dangling Pointer
{ D. The program may crash as free() is called
char *p = calloc(100, 1); for NULL pointer.
p = "welcome";
printf("%s\n", p); 216. Which languages necessarily need heap
} allocation in the run time environment? .
A. error [ISRO]
B. welcome A. Those that support recursion
C. memory location stored by the pointer B. Those that use dynamic scoping
D. junk value C. Those that use global variables
D. Those that allow dynamic data structures
214. Predict the output.
# include<stdio.h> 217. What is the output of the following code
# include<stdlib.h> if it is executed on a 32 bit processor?
void fun(int *a) #include<stdio.h>//32-bit compiler
{ #include<stdlib.h>
a = (int*)malloc(sizeof(int)); int main()
} {
int main() int *p;
{ p = (int *)malloc(20);
int *p; printf("%d\n", sizeof(p));
fun(p); free(p);
*p = 6; return 0;
printf("%dn",*p); }
return(0); A. 2 B. 4
} C. 8 D. Junk value
A. Program will not work
B. Works and prints 6 218. The number of arguments taken as
C. Error input which allocating memory dynamically
D. None using malloc() is ___________
A. 0
B. 1
38
C. 2
D. 3 222. Suppose we have a one dimensional
array, named ‘x’, which contains 10
219. If malloc() and calloc() are not type integers. Which of the following is the
casted, the default return type is correct way to allocate memory dynamically
___________ to the array ‘x’ using malloc()?
A. void* B. void**
C. int* D. char* A. x=(int*)malloc(10);
B. x=(int*)malloc(10,sizeof(int));
220. What is the output of the following C. x=malloc(int 10,sizeof(int));
code? (Given that the size of array is 4 and D. x=(int*)malloc(10*sizeof(int));
new size of array is 5)
#include<stdio.h> 1.13 FILES
#include<stdlib.h>
main() 223. Which of the following true about FILE
{ *fp
int *p,i,a,b; A. FILE is a keyword in C for representing
printf("Enter size of array"); files and fp is a variable of FILE type.
scanf("%d",&a); B. FILE is a stream
p=(int*)malloc(a*sizeof(int)); C. FILE is a buffered stream
for(i=0;i<a;i++) D. FILE is a structure and fp is a pointer to the
printf("%d\n",i); structure of FILE type
printf("Enter new size of array");
scanf("%d",&b); 224. FILE is of type ______
realloc(p,b); A. int type
for(i=0;i<b;i++) B. char * type
printf("%d\n",i); C. struct type
free(p); D. None of the mentioned
}
A. 1234 225. fseek() should be preferred over
12345 rewind() mainly because
B. Error A. rewind() doesn't work for empty files
C. 0123 B. rewind() may fail for large files
01234 C. In rewind, there is no way to check if the
D. 0123 operations completed successfully
12345 D. All of the above
221. If the space in memory allocated by 226. What is the purpose of "rb" in fopen()
malloc is not sufficient, then an allocation function used below in the code?
fails and returns ___________ FILE *fp;
A. NULL pointer fp = fopen("demo.txt", "rb");
B. Zero A. Open "demo.txt" in binary mode for reading
C. Garbage value B. Create a new file "demo.txt" for reading and
D. The number of bytes available writing
39
C. Open "demo.txt" in binary mode for reading printf("%c",c);
and writing fclose(fp);
D. None of the above return 0;
}
227. Which files will get closed through the A. hello you are reading a file
fclose() in the following program? B. hello you are reading a file demo
void main() C. demo
{ D. None of the above
FILE *fp, *ft;
fp = fopen("a.txt", "r"); 230. Predict the output of the following
ft = fopen("b.txt", "r"); void main() [Capgemini]
fclose(fp,ft); {
} FILE *fp=stdout;
A. a, b B. a int n;
C. b D. Error in fclose fprintf(fp,"%d ",45);
fprintf(stderr,"%d ",65);
228. What is the output of this program? }
#include<stdio.h> A.45 65 B.65
int main(){ C.compilation error D.65 45
FILE *fp;
char *str; 231. What is the output of this code .
fp=fopen("demo.txt","r"); [Capgemini]
// demo.txt :you are a good programmer #include<stdio.h>
while(fgets(str,6,fp)!=NULL) #include<string.h>
puts(str); int main()
fclose(fp); {
return 0; char line[3];
} FILE *fp;
A. you are a good programmer fp=fopen("newfile.txt","r");
B. e a good programmer while(fgets(line,3,fp))
C. you ar fputs(line,stdout);
D. you are return 0;
}
229. What is the output of this program? A. Compile time error
#include<stdio.h> B. Segmentation fault
int main(){ C. Infinite loop
char c; D. No of lines present in file newfile
FILE *fp;
fp=fopen("demo.txt","a+"); 232. What will be printed on the
// demo.txt : hello you are reading a file screen[capgemini]
fprintf(fp," demo"); #include<stdio.h>
fclose(fp); int main()
fp=fopen("myfile.txt","r"); {
while((c=fgetc(fp))!=EOF) char n[20];
40
fgets(n,19,stdin);
ungetc(n[0],stdin);
scanf("%s",n);
printf("%s\n",n);
return 0;
}
A. Whatever string user types second time
B. Compile time error
C. First character of whatever user types first
time and whatever user types second time
D. Error
Task
Constraints
1<=length<=1000
1<=age<=100
41
Linked List
C. pointer to the last record of the actual data
D. middle record of the actual data
1.14 LISTS
239. What would be the asymptotic time
233. Linked lists are best suited ….. complexity to add an element in the linked
A. for relatively permanent collections of data. list?
B. for the size of the structure and the data in A. O(1)
the structure are constantly changing. B. O(n)
C. data structure C. O(n2)
D. for none of above situation D. none
234. The operation of processing each 240. Consider the following definition in c
element in the list is known as …… programming language
A. sorting struct node
B. merging {
C. inserting int data;
D. traversal struct node * next;
}
235. The situation when in a linked list typedef struct node NODE;
START=NULL is …. NODE *ptr;
A. Underflow Which of the following c code is used to
B. Overflow create new node?
C. Houseful A. ptr = (NODE*)malloc(sizeof(NODE));
D. Saturated B. ptr = (NODE*)malloc(NODE);
C. ptr = (NODE*)malloc(sizeof(NODE*));
236. ………. may take place only when there D. ptr = (NODE)malloc(sizeof(NODE));
is some minimum amount(or) no space left
in free storage list. 241. What kind of linked list is best to
A. Memory management answer question like “What is the item at
B. Garbage collection position n?”
C. Recycle bin A. Singly linked list
D. Memory management B. Doubly linked list
C. Circular linked list
237. Indexing the …….. element in the list is D. Array implementation of linked list
not possible in linked lists.
A. middle 242. What does the following function do for
B. first a given Linked List with first node as head?
C. last void fun1(struct node* head)
D. any where in between {
if(head == NULL)
238. The dummy header in linked list return;
contain ….. [zoho] fun1(head->next);
A. first record of the actual data printf("%d ", head->data);
B. last record of the actual data }
42
A. Prints all nodes of linked lists {
B. Prints all nodes of linked list in reverse if(start == NULL)
order return;
C. Prints alternate nodes of Linked List printf("%d ", start->data);
D. Prints alternate nodes in reverse order if(start->next != NULL )
fun(start->next->next);
243. The following function reverse() is printf("%d ", start->data);
supposed to reverse a singly linked list. }
There is one line missing at the end of the A.1 4 6 6 4 1 B.1 3 5 1 3 5
function. [Infosys] C.1 2 3 5 D.1 3 5 5 3 1
/* Link list node */
struct node 245. The following C function takes a single-
{ linked list of integers as a parameter and
int data; rearranges the elements of the list.
struct node* next; The function is called with the list containing
}; the integers 1, 2, 3, 4, 5, 6, 7 in the given order.
/* head_ref is a double pointer which points to What will be the contents of the list after the
head (or start) pointer function completes execution?
of linked list */ struct node
static void reverse(struct node** head_ref) { int value;
{ struct node *next;
struct node* prev = NULL; };
struct node* current = *head_ref; void rearrange(struct node *list)
struct node* next; {
while (current != NULL) struct node *p, * q;
{ int temp;
next = current->next; if ((!list) || !list->next)
current->next = prev; return;
prev = current; p = list;
current = next; q = list->next;
} while(q)
/*ADD A STATEMENT HERE*/ } {temp = p->value;
What should be added in place of “/*ADD A p->value = q->value;
STATEMENT HERE*/”, so that the function q->value = temp;
correctly reverses a linked list. p = q->next;
A. *head_ref = prev; q = p?p->next:0;
B. *head_ref = current; }}
C. *head_ref = next; A. 1, 2, 3, 4, 5, 6, 7
D. *head_ref = NULL; B. 2, 1, 4, 3, 6, 5, 7
C. 1, 3, 2, 5, 4, 7, 6
244. What is the output of following function D. 2, 3, 4, 5, 6, 7, 1
for start pointing to first node of following
linked list? 1->2->3->4->5->6 246. Consider the following doubly linked
void fun(struct node* start) list: head-1-2-3-4-5-tail
43
What will be the list after performing the while((temp != head) && (!(temp.getItem()
given sequence of operations? == data)))
Node temp = new { temp = temp.getNext();
Node(6,head,head.getNext()); flag = 1;
head.setNext(temp); break;
temp.getNext().setPrev(temp); }}
Node temp1 = tail.getPrev(); if(flag)
tail.setPrev(temp1.getPrev()); System.out.println("success");
temp1.getPrev().setNext(tail); else
A. head-6-1-2-3-4-5-tail System.out.println("fail");
B. head-6-1-2-3-4-tail }
C. head-1-2-3-4-5-6-tail A. Print success if a particular element is not
D. head-1-2-3-4-5-tail found
B. Print fail if a particular element is not found
247. What is the time complexity of C. Print success if a particular element is equal
searching for an element in a circular linked to 1
list? D. Print fail if the list is empty
A. O(n)
B. O(nlogn) 250. consider the function f defined here:
C. O(1) struct item
D. None of the mentioned {
int data;
248. Consider a small circular linked list. struct item * next;
How to detect the presence of cycles in this };
list effectively? int f (struct item *p)
A. Keep one node as head and traverse another {
temp node till the end to check if its ‘next return((p==NULL) ||((p->next==NULL)||(p-
points to head >data<=p->next->data) && (p->next)));
B. Have fast and slow pointers with the fast }
pointer advancing two nodes at a time and slow For a given linked list p, the function f returns
pointer advancing by one node at a time 1 if and only if
C. Cannot determine, you have to pre-define if A. the list is empty or has exactly one element
the list contains cycles B. the element in the list are sorted in non-
D. None of the mentioned decreasing order of data value
C. the element in the list are sorted in non-
249. What is the functionality of the increasing order of data value
following piece of code? Select the most D. not all element in the list have the same data
appropriate. [TCS] value
public void function(int data)
{ 251. Consider the following definition in c
int flag = 0; programming language
if( head != null) struct node
{ Node temp = head.getNext(); {
int data;
44
struct node * next; C. A*BC+/D D.ABCD+/*
}
typedef struct node NODE; 256. The result of evaluating the postfix
NODE *ptr; expression 5, 4, 6, +, *, 4, 9, 3, /, +, * is?
Which of the following c code is used to create A.600 B.350
new node? C.650 D.588
A. ptr=(NODE*)malloc(sizeof(NODE));
B. ptr=(NODE*)malloc(NODE); 257. Consider the linked list implementation
C. ptr=(NODE*)malloc(sizeof(NODE*)); of a stack. Which of the following node is
D. ptr=(NODE)malloc(sizeof(NODE)); considered as Top of the stack?
A.First node B.Last node
252. What does the following function do for C.Any node D.Middle node
a given Linked List with first node as head?
void fun1(struct node* head) 258. Consider the following operation
{ performed on a stack of size 5.
if(head == NULL) Push(1);
return; Pop();
Push(2);
fun1(head->next); Push(3);
printf("%d ", head->data); Pop();
} Push(4);
A. Prints all nodes of linked lists Pop();
B. Prints all nodes of linked list in reverse Pop();
order Push(5);
C. Prints alternate nodes of Linked List After the completion of all operation, the no of
D. Prints alternate nodes in reverse order element present on stack are
A.1 B.2
1.15 STACKS C.3 D.4
253. The postfix form of the expression (A+ 259. Consider the following array
B)*(C*D- E)*F / G is implementation of stack:
A. AB+ CD*E - FG /** #define MAX 10
B. AB + CD* E - F **G / Struct STACK
C. AB + CD* E - *F *G / {Int arr [MAX];
D. AB + CDE * - * F *G / Int top = -1;
} If the array index starts with 0, the maximum
254. The data structure required to check value of top which does not cause stack
whether an expression contains balanced overflow is?
parenthesis is? A.8 B.9
A.Stack B.Queue C.10 D.11
C.Array D.Tree
260. Consider the usual implementation of
255. The postfix form of A*B+C/D is? parentheses balancing program using stack.
A.*AB/CD+ B.AB*CD/+ What is the maximum number of
45
parentheses that will appear on stack at any 263. The five items: A, B, C, D, and E are
instance of time during the analysis of ( ( ) ( ( pushed in a stack, one after other starting
) ) ( ( ) ) )? from A. The stack is popped four items and
A.1 B.2 each element is inserted in a queue. The two
C.3 D.4 elements are deleted from the queue and
pushed back on the stack. Now one item is
261. Which one of the following is an popped from the stack. The popped item is
application of Stack Data Structure? A.A B.B
A. Managing function calls C.C D.D
B. The stock span problem
C. Arithmetic expression evaluation 264. What is the result of the following
D. All of the above operation Top (Push (S, X))
A.X B.Null
262. Consider the following C program: C.S D.None of the mentioned
#define EOF -1
void push (int); /* push the argument on 1.16 QUEUES
the stack */
int pop (void); /* pop the top of the 265. A linear list of elements in which
stack */ deletion can be done from one end (front)
void flagError (); and insertion can take place only at the
int main () other end (rear) is known as a ?
{ int c, m, n, r; A.Queue B.Stack
while ((c = getchar ()) != EOF) C.Tree D.Linked list
{ if (isdigit (c) )
push (c); 266. Let the following circular queue can
else if ((c == '+') || (c == '*')) accommodate maximum six elements with
{ m = pop (); the following data front = 2 rear = 4. queue =
n = pop (); _______; L, M, N, ___, ___
r = (c == '+') ? n + m : n*m; What will happen after ADD O operation takes
push (r); place?
} A. front = 2 rear = 5
else if (c != ' ') queue = ______; L, M, N, O, ___
flagError (); B. front = 3 rear = 5
} queue = L, M, N, O, ___
printf("% c", pop ()); C. front = 3 rear = 4
} queue = ______; L, M, N, O, ___
What is the output of the program for the D. front = 2 rear = 4
following input ? 5 2 * 3 3 2 + * + queue = L, M, N, O, ___
A. 15
B. 25 267. A queue is a ?
C. 30 A. FIFO (First In First Out) list
D. 150 B. LIFO (Last In First Out) list.
C. Ordered array
D. Linear tree
46
m=k;
268. In Breadth First Search of Graph, while(Q is not empty) and (m > 0)
which of the following data structure is {
used? DEQUEUE(Q)
A.Stack B.Queue m=m-1
C.Linked list D.None }}
What is the worst case time complexity of a
269. In the array implementation of circular sequence of n queue operations on an initially
queue, which of the following operation take empty queue?
worst case linear time? A.θ (n) B.θ (n + k)
A.Insertion B.Deletion C.θ (nk) D.θ (n2)
C.To empty a queue D.None
273. Which of the following is not the type of
270. If the MAX_SIZE is the size of the queue?
array used in the implementation of circular A. Ordinary queue
queue. How is rear manipulated while B. Single ended queue
inserting an element in the queue? C. Circular queue
A. rear=(rear%1)+MAX_SIZE D. Priority queue
B. rear=rear%(MAX_SIZE+1)
C. rear=(rear+1)%MAX_SIZE 274. Queues serve major role in
D. rear=rear+(1%MAX_SIZE) A. Simulation of recursion
B. Simulation of arbitrary linked list
271. Suppose a circular queue of capacity C. Simulation of limited resource allocation
(n-1) elements is implemented with an array D. All of the mentioned
of n elements. Assume that the insertion and
deletion operations are carried out using 275. Following is C like pseudo code of a
REAR and FRONT as array index function that takes a Queue as an argument,
variables, respectively. Initially and uses a stack S to do processing.
REAR=FRONT=0. The conditions to detect void fun(Queue *Q)
queue full and queue is empty are? {
A. Full: (REAR+1)mod n == FRONT Stack S; // Say it creates an empty stack S
Empty: REAR==FRONT // Run while Q is not empty
B. Full: (REAR+1)mod n == FRONT while (!isEmpty(Q))
Empty: (FRONT+1) mod n == REAR {
C. Full: REAR==FRONT // deQueue an item from Q and push the
Empty: (REAR+1) mod n==FRONT dequeued item to S
D. Full: (FRONT+1)mod n==REAR push(&S, deQueue(Q));
Empty: REAR==FRONT } // Run while Stack S is not empty
while (!isEmpty(&S))
272. Consider the following operations along {
with ENQUEUE and DEQUEUE operations // Pop an item from S and enqueue the
queues, where k is a global parameter. poppped item to Q
Multiqueue(Q) enQueue(Q, pop(&S));
{ }}
47
What does the above function do in general? B. 20, 18, 17, 12, 13, 10, 15
A. Removes the last from Q C. 20, 18, 17, 10, 12, 13, 15
B. Keeps the Q same as it was before the call D. 20, 18, 17, 13, 12, 10, 15
C. Makes Q empty
D. Reverses the Q 279. A normal queue, if implemented using
an array of size MAX_SIZE, gets full when
276. How many stacks are needed to A. Rear = MAX_SIZE – 1
implement a queue. Consider the situation B. Front = (rear + 1)mod MAX_SIZE
where no other data structure like arrays, C. Front = rear + 1
linked list is available to you. D. Rear = front
A.1 B.2
C.3 D.4
Can you crack it?
277. Consider the following pseudo code.
Assume that IntQueue is an integer queue. T ask
What does the function fun do? Write a program to validate if the input string
void fun(int n) has redundant braces?
{
IntQueue q = new IntQueue(); Return 0/1
q.enqueue(0); 0 -> NO
q.enqueue(1); 1 -> YES
for (int i = 0; i < n; i++)
{ Input will be always a valid expression
int a = q.dequeue();
int b = q.dequeue(); and operators allowed are only + , * , - , /
q.enqueue(b);
q.enqueue(a + b); Example:
ptint(a);
} ((a + b)) has redundant braces so answer will
} be 1
A. Prints numbers from 0 to n-1 (a + (a + b)) doesn't have have any redundant
B. Prints numbers from n-1 to 0 braces so answer will be 0
C. Prints first n Fibonacci numbers
D. Prints first n Fibonacci numbers in reverse
order.
48
Trees
285. With an ideal balance, the running time
1.17 TREES for inserts, searches and deletes, even in the
worst case is ………………………
280. For finding a node in a A.log₂n B.n
…………………, at each stage we ideally C.log₂(n+1) D.n+1
reduce the number of nodes we have to
check by half. 286. In binary search tree, a
A. binary tree …………………. exists if starting from some
B. binary search tree node n there exists a path that returns to n.
C. AVL tree A.cycle B.node
D. binary heap tree C.root D.subtree
281. In the best case of BST, the time is on 287. In binary search tree, a
the order of ……………………, but in the …………………… rooted to node n is the
worst case it requires linear time. tree formed by imaging node n was a root.
A.Log₂n B.n A.cycle B.node
C.Log₂(n+1) D.n+1 C.root D.subtree
49
B. AVL
291. A lemma is a red-black tree with n C. binary search
internal nodes has height at most D. binary heap
……………
A.2lg(n) B.2n 296. While deleting nodes from a binary
C.2lg(n+1) D.n+1 heap, …………………. node is replaced by
the last leaf in the tree.
292. While inserting into A.left leaf B.right leaf
………………………….., insertions are done C.root D.cycle
at a leaf and will replace an external node
with an internal node with two external 297. The worst case height of an AVL tree
children. with n nodes is ……………
A. red-black tree A.2 lg n B.1.39 lg n
B. AVL tree C.1.44 lg n D.1.64 lg n
C. binary search tree
D. binary heap tree 298. Postfix expression for (A+B) *(C+D) is
A. A B C * + D +
293. For an AVL tree B. A B + C D + *
………………………….. is the additional C. ABCD++*
piece of information which indicates if the D. None
difference in height between the left and
right subtree is the same or if not, which of 299. Match the following for binary tree
the two subtrees has height one unit larger. traversal
A. tree factor
B. balance factor
(1) Pre Order (A)Left Right Root
C. additional factor
D. unit factor
(2) In Order (B)Left Root Right
294. ………………… is a complete binary
(2) Post
tree, that is completely filled except possibly
Order (C)Root Left Right
at the bottom level.
A. Red-Black Tree
B. AVL Tree A. 1 → A, 2 → B, 3→C
C. Binary Heap Tree B. 1 → C, 2 → B, 3→A
D. A-A Tree C. 1 → A, 2 → C, 3→B
D. 1 → B, 2 → A, 3→C
295. An insertion into a
………………………. is performed by 300. In the following answers, the operator
inserting the new node in the location '^' indicates power.
referenced by next in the array and then A.2^(i)-1 B.2^i
“sifting it up” by comparing the key of the C.2^(i+1) D.2^[(i+1)/2]
newly inserted node with the key of the
parent. 301. Post-order traversal of a given binary
A. red-black search tree, T produces the following
50
sequence of keys 10, 9, 23, 22, 27, 25, 15, 50, on natural numbers. What is the in-order
95, 60, 40, 29 Which one of the following traversal sequence of the resultant tree?
sequences of keys can be the result of an in- A. 7 5 1 0 3 2 4 6 8 9
order traversal of the tree T? (GATE CS B. 0 2 4 3 1 6 5 9 8 7
2005) C. 0 1 2 3 4 5 6 7 8 9
A. 9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95 D. 9 8 6 4 2 3 0 1 5 7
B. 9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29
C. 29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95 305. Consider the following code snippet in
D. 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29 C. The function print() receives root of a
Binary Search Tree (BST) and a positive
302. The following three are known to be the integer k as arguments.
preorder, inorder and postorder sequences struct node {
of a binary tree. But it is not known which is int data;
which. struct node *left, *right;
MBCAFHPYK };
KAMCBYPFH int count = 0;
MABCKYFPH. Pick the true statement from void print(struct node *root, int k)
the following. { if (root != NULL && count <= k)
A I and II are preorder and inorder sequences, respectively{ print(root->right, k);
B I and III are preorder and postorder sequences, respectively count++;
II is the inorder sequence, but nothing more can be said about
if (count
the other
== k)two
C
sequences printf("%d ", root->data);
D II and III are the preorder and inorder sequences, respectively print(root->left, k);
}}
303. In the balanced binary tree in the below What is the output of print(root, 3) where root
figure, how many nodes will become represent root of the following BST.
unbalanced when a node is inserted as a 15
child of the node “g”? /
a 10 20
/ / /
b e 8 12 16 25
/ / A.10 B.16
c d f C.20 D.20 10
/
g 306. Consider the following binary search
A 1 tree T given below: Which node contains the
B 3 fourth smallest element in
C 7
D 8
51
D. Disks are more reliable than memory
307. Which of the following is a self-
adjusting or self-balancing Binary Search 312. Consider the following 2-3-4 tree (i.e.,
Tree B-tree with a minimum degree of two) in
A. Splay Tree which each data item is a letter. The usual
B. AVL Tree alphabetical ordering of letters is used in
C. Red Black Tree constructing the
D. All of the above tree.
52
respectively. The postorder traversal of the
313. With reference to the B+ tree index of binary tree is:
order 1 shown below, the minimum number A. d e b f g c a
of nodes (including the root node) that must B. e d b g f c a
be fetched in order to satisfy the following C. e d b f g c a
query: “Get all records with a search key D. d e f g b c a
greater than or equal to 7 and less than 15”
is ________ 316. What does the following function do for
a given binary tree?
int fun(struct node *root)
{
if (root == NULL)
return 0;
if (root->left == NULL && root->right ==
1.18 TREE TRAVERSALS NULL)
return 0;
314. Following function is supposed to return 1 + fun(root->left) + fun(root->right);
calculate the maximum depth or height of a }
Binary tree -- the number of nodes along the A. Counts leaf nodes
longest path from the root node down to the B. Counts internal nodes
farthest leaf node. C. Returns height where height is defined as
int maxDepth(struct node* node) number of edges on the path from root to
{ deepest node
if (node==NULL) D. Return diameter where diameter is
return 0; number of edges on the longest path between
else any two nodes.
{/* compute the depth of each subtree */
int lDepth = maxDepth(node->left); 317. Consider the following C program
int rDepth = maxDepth(node->right); segment.
/* use the larger one */ struct CellNode
if (lDepth > rDepth) {
return X; struct CelINode *leftchild;
else return Y; int element;
}} struct CelINode *rightChild;
What should be the values of X and Y so that }
the function works correctly? int Dosomething(struct CelINode *ptr)
A. X = lDepth, Y = rDepth {
B. X = lDepth + 1, Y = rDepth + 1 int value = 0;
C. X = lDepth - 1, Y = rDepth -1 if (ptr != NULL)
D. None of the above {{ if (ptr->leftChild != NULL)
. value = 1 + DoSomething(ptr->leftChild);
315. The inorder and preorder traversal of a if (ptr->rightChild != NULL)
binary tree are d b e a f c g and a b d e c f g, value = max(value, 1 + DoSomething(ptr-
>rightChild));
53
} return (value);} adbcgef
The value returned by the function A Depth First Search (DFS) is started at node
DoSomething when a pointer to the root of a a. The nodes are listed in the order they are first
non-empty tree is passed as argument is visited. Which all of the above is (are) possible
(GATE CS 2004) output(s)?
A. The number of leaf nodes in the tree
B. The number of nodes in the tree
C. The number of internal nodes in the tree
D. The height of the tree
54
"Menu" has been printed 6 times
C &DS Answers
4. B
Explanation:
Answers:
There are two printf statements...
1. C The first one actually prints what the second
Explanation: printf function returns. printf function returns
%sincludehelp includehelp. After pre- the length of message being printed by the
processing phase of compilation, printf printf function. The second printf function
statement will become. printf executes first & hence it prints "includehelp"
("%sincludehelp ","%sincludehelp "), It whereas, the first printf prints 11 then, which is
prints "%sincludehelp includehelp" the length of the message printed by second
print function.
2. D So, output is "includehelp11"
3. B 5. A
Explanation:
n=0 6. B
0th iteration: Explanation:
Prints "Menu" returns 5 //count of "Menu" \b Causes Cursor Position to Move on Last ‘t’.
printing 1 and then “er” is Printed Final String is
n<5 “Diicketer”
n=n+1=1 \r Causes Cursor to Move on First Position in
1st iteration: Same Line and then “Cr” is Overwritten on
Prints "Menu" returns 5 //count of "Menu" “Di” So Finally Output is “Cricketer”
printing 2
n<5 7. C
n=n+1=2 8. B
2nd iteration: Explanation:
Prints "Menu" returns 5 //count of "Menu" Printf Returns the Length of String specified in
printing 3 Double Quotes
n<5 Consider first printf , Length of String
n=n+1=3 specified in first printf i.e “%d” is 2
3rd iteration: It starts printing the String Skipping the
Prints "Menu" returns 5 //count of "Menu" number of Characters specified before ‘+’ sign
printing 4 printf(1+”%d”) skips “%” character and only
n<5 prints ‘d’ as output.
n=n+1=4
4th iteration: 9. B
Prints "Menu" returns 5 //count of "Menu" Explanation: It skips the var.
printing 5
n<5 10. B
n=n+1=5 11. C
5th iteration: 12. B
Prints "Menu" returns 5 //count of "Menu" Explanation: The minimum field width and
printing 6 precision specifiers are usually constants. They
N is not <5 can also be provided by arguments to printf().
Thus program terminates
55
This is done by using * modifier as shown in 33. D
the given code. 34. A
13. C 35. B
14. A
36. C
Explanation: 0 in the above code is Flags. The
number is left-padded with zeros(0) instead of 37. A
spaces. 38. C
15. A 39. B
16. C Explanation: The main theme of the program
lies here: sizeof(k /= i + j). An expression
17. C doesn’t get evaluated inside sizeof operator.
Explanation: The crux of the program lies in sizeof operator returns sizeof(int) because the
the expression: 5[“GeeksQuiz”] result of expression will be an integer. As the
This expression is broken down by the expression is not evaluated, value of k will not
compiler as: *(5 + “GeeksQuiz”). Adding 5 to be changed.
the base address of the string increments the 40. A
pointer(lets say a pointer was pointing to the Explanation: The bracket operator has higher
start(G) of the string initially) to point to Q. precedence than assignment operator. The
Applying value-of operator gives the character expression within bracket operator is evaluated
at the location pointed to by the pointer i.e. Q. from left to right but it is always the result of
the last expression which gets assigned.
18. A 41. A
Explanation: 42. A
printf() returns the number of characters 43. C
successfully printed on the screen. 44. A
45. D
19. B 46. C
Explanation: 47. B
printf (“\n%d”, 1 + x ++); 48. C
In the following C program There is post 49. B
increment operation: So, printf will print 1 + Explanation: Let us consider the condition
128 as output. ++ will increment the x value inside the if statement. Since there are two
i.e. x = 129. greater than (>) operators in expression “c > b
> a”, associativity of > is considered.
20. A
Associativity of > is left to right. So,
21. B
22. C expression c > b > a is evaluated as ( (c > b) > a
23. B ) which is false.
24. B 50. D
25. D 51. D
26. B 52. D
27. D 53. B
28. D
54. C
29. D
30. A 55. C
Explanation: The symbol ^ when used before 56. D
a escape sequence, does not read from the 57. C
console 58. A
31. B 59. C
32. A 60. C
56
Explanation: most recently assigned value (#define i 10) will
A static variable is shared among all calls of a be taken.
function. All calls to main() in the given 69. C
program share the same i. i becomes 0 before Explanation: Preprocessor in any
the printf() statement in all calls to main(). programming language executes as a separate
61. C pass before the execution of the compiler. So
Explanation: textual replacement of clrscr() to 17 occurs
See following declarations to know the with no errors.
difference between constant pointer and a 70. C
pointer to a constant. int * const ptr —> ptr is Explanation: Expected unqualified-id before
constant pointer. You can change the value at numeric constant error will occur. Though 30;
the location pointed by pointer p, but you can is an executable statement inside main()
not change p to point to other location. int function, it won't outside the main() function.
const * ptr —> ptr is a pointer to a constant. U can use “#define x 30” instead of “30;”.
You can change ptr to point other variable. But 71. D
you cannot change the value pointed by ptr. Explanation: Preprocessor should not
Therefore above program works well because terminate with semicolon.
we have a constant pointer and we are not 72. B
changing ptr to point to any other location. We Explanation: enum assigns numbers starting
are only incrementing value pointed by ptr. from 0, if not explicitly defined by some other
integer.
62. D 73. C
Explanation: Explanation:#define CONDITION(x) must be
There is no problem with the program. It terminated my backslash (\) to follow the next
simply creates a user defined type i and creates line.
a variable a of type i. 74. C
63. B Explanation: #define CONDITION(x) ends
64. B with backslash(/). So that next line following
65. D #define CONDITION(x) will be consider by
Explanation: Since the #define replaces the the C compiler and prints lets findcourse.
string int by the macro char 75. A
66. A 76. B
Explanation: Since we replace x = 27 in 77. B
#define. 78. B
67. D 79. C
Explanation: Operators enjoys priority / is
given more priority over *. In this program the Both statements should be true in and(&&)
execution takes place in this format. operation and atleast one expression should be
27 / square(3)=>27 / 3*3=>27 / 3*3=>9 * true in or(||) operator.
3=>27
80. D
68. B 81. B
Explanation: The preprocessor directives can 82. B
be redefined anywhere in the program. So the 83. C
57
Explanation: At first zero will assign in ‘i’ 107. B
then comma operator returns the last value 108. C
which is 3 and condition becomes true. Explanation:
The program goes in an infinite loop because n
84. A is never zero when loop condition (n != 0) is
85. A checked. n changes like 7 5 3 1 -1 -3 -5 -7 -9 ...
86. A 109. D
87. B Explanation:
88. A It gives you an infinite loop.
Explanation: if(x=10)... "=" is an assignment 110. D
operator, so 10 will be assigned to x and 111. C
condition will be true due to if(10). Explanation:
The result will be 1 but after a really long time
89. C
90. A because while loop will keep on going until i
becomes 4294967295 (Assuming unsigned int
Explanation:
Any non zero value is treated as true for is stored using 4 bytes) and as i highest limit of
condition. unsigned int is 4294967295 in next ++
Consider the expressions: if( (-100 && operation it will become zero and we'll come
100)||(20 && -20) ) out of loop and 1 will be printed. Since the time
=if( (1) || (1) ) taken is long, on-line compiler may terminate
the program with time limit exceeded error. If
=if(1)
instead of unsigned int, you use unsigned short
91. D int then result (1) may come faster.
112. B
92. A
93. C 113. C
94. A 114. A
115. B
95. D
Explanation: strcmp return Zero, because both
96. B the strings are same. If(0) return false then it
97. B goes to else.
98. A 116. B
99. A 117. C
The while loop have semicolon at the end, so 118. A
the loop is increments and check the condition 119. D
till the unsigned reaches its range 120. A
[0 - 4294967295], after the limit exceeds it 121. D
again go to default value 0. So, i will be set to 0 Explanation:
then i++. Variable i will be 1. Let us consider below line inside the for loop
100. B p[i] = s[length — i]; For i = 0, p[i] will be s[6
101. C — 0] and s[6] is ‘\0′ So p[0] becomes ‘\0’. It
doesn't matter what comes in p[1], p[2]….. as
102. D
P[0] will not change for i >0. Nothing is
103. D printed if we print a string with first character
104. B ‘\0′.
105. D 122. C
106. C Explanation:
58
char c[] = "GATE2011"; // p now has the base Note: to terminate enter any key from
address string "GATE2011" keyboard(getch)
char *p = c; // p[3] is 'E' and p[1] is 'A'. 144. A
// p[3] - p[1] = ASCII value of 'E' - ASCII
145. C
value of 'A' = 4
// So the expression p + p[3] - p[1] becomes p 146. A
+ 4 which is 147. A
// base address of string "2011" printf("%s", p 148. A
+ p[3] - p[1]); // prints 2011 149. C
123. C 150. B
124. C 151. A
Explanation:
152. A
char s1[7] = "1234", *p; p = s1 + 2; // p
153. B
holds address of character 3
154. B
*p = '0' ; // memory at s1 + 3 now becomes 0.
155. B
printf ("%s", s1); // All characters are printed
Explanation:
125. A
This is a simple program with function
126. A
127. C pointers. fun is assigned to point to demo. So
128. D the two statements "(*fun)();" and "fun();"
129. A mean the same thing.
130. A 156. B
131. B Explanation:
132. B extern keyword is used for global variables.
133. B Functions are global anyways, so adding extern
Explanation: doesn't add anything.
The function fun() basically counts number of
characters in input string. Inside fun(), pointer 157. A
str2 is initialized as str1. The statement
158. C
while(*++str1); increments str1 till ‘\0’ is
reached. str1 is incremented by 9. Finally the Explanation:
difference between str2 and str1 is returned Since i is static, first line of f() is executed only
which is 9. once.
134. C Execution of f(1)
135. B i=1
136. A
n=2
137. A
i=2
138. D
Call f(2)
Explanation: i=2
p is a pointer to a "constant integer". But we n=4
tried to change the value of the
i=3
"constant integer".
Call f(4)
139. A
i=3
140. B
n=7
141. C i=4
142. C
Call f(7)
143. B
since n >= 5 return n(7) with return value = 7.
159. B
59
Explanation: the following statement initializes an array of
Step 1: int i=5, j=2; Here variable i and j are size 1000 with values as 0. int arr[1000] = {0};
declared as an integer type and initialized to 5
and 2 respectively. 165. C
Step 2: fun(&i, &j); Here the function fun() is 166. D
called with two parameters &i and &j (The & 167. B
denotes call by reference. So the address of the Explanation: In C, initialization of array can
variable i and j are passed. ) be done for selected elements as well. By
Step 3: void fun(int *i, int *j) This function is default, the initializer start from 0th element.
called by reference, so we have to use * before Specific elements in array can be specified by
the parameters. []. It should be noted that the remaining
Step 4: *i = *i**i; Here *i denotes the value of elements (i.e. the ones not mentioned in array
the variable i. We are multiplying 5*5 and initialization) would be initialized to 0. For
storing the result 25 in same variable i. example, “int arr[10] = {100,
Step 5: *j = *j**j; Here *j denotes the value of [5]=100,[9]=100}” is also legal in C. This
the variable j. We are multiplying 2*2 and initializes arr[0], arr[5] and arr[9] to 100. All
storing the result 4 in same variable j. the remaining elements would be 0.
Step 6: Then the function void fun(int *i, int *j) 168. C
return back the control back to main() function. Explanation: An array whose size is specified
Step 7: printf("%d, %d", i, j); It prints the value as variable can’t be defined out any function. It
of variable i and j. can be defined only inside a function. So
Hence the output is 25, 4. putting arr[size] outside main() would result in
compile error.
160. A 169. A
Explanation: Explanation:
Step 1: int i; The variable i is declared as an Step 1: int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8,
integer type.
9, 0}; The variable a is declared as an
Step 1: int fun(); This prototype tells the
multidimensional integer array with size of 3
compiler that the function fun() does not accept
rows 4 columns.
any arguments and it returns an integer value. Step 2: int *ptr; The *ptr is a integer pointer
Step 1: while(i) The value of i is not initialized variable.
so this while condition is failed. So, it does not Step 3: ptr = &a[0][0]; Here we are assigning
execute the while block. the base address of the array a to the pointer
Step 1: printf("Hello\n"); It prints "Hello". variable *ptr.
Hence the output of the program is "Hello". Step 4: fun(&ptr); Now, the &ptr contains the
base address of array a.
161. A Step 4: Inside the function fun(&ptr); The
162. A printf("%d\n", **p); prints the value '1'.
163. B because the *p contains the base address or the
164. B first element memory address of the array a (ie.
Explanation: In C/C++, if we initialize an array a[0])
with fewer members, all remaining members
**p contains the value of *p memory location
are automatically initialized as 0. For example, (ie. a[0]=1).
Hence the output of the program is '1'.
60
170. C points to second element. ary+2 points to the
171. B third element
Explanation:
Since C is a compiler dependent language, it 182. C
may give different outputs at different Explanation:
platforms. We have given the TurboC It is same as *(*(*(ary+i)+ )+k) = ary[i][j][k]
Compiler (Windows) output.
Please try the above programs in Windows 183. A
(Turbo-C Compiler) and Linux (GCC 184. A
Compiler), you will understand the difference 185. D
better. 186. C
172. D 187. C
Explanation: Whenever a particular memory 188. D
location is referred, it is likely that the locations 189. D
nearby are also referred, arrays are stored as 190. C
contiguous blocks in memory, so if you want to 191. A
access array elements, spatial locality makes it 192. B
to access quickly. 193. A
173. B STRUCTURES
174. D 194. A
175. D 195. A
176. D 196. B
177. C 197. A
178. B 198. C
Explanation: 199. A
0.2%f prints only two decimal points. It is Note: p & p1 are having different user-defined
allowed to use float values with arrays data types.
200. C
179. B 201. C
Explanation: You can use increment and 202. A
decrement operators on array variables too. 203. D
180. C 204. B
Explanation: 205. B
206. C
Notice that function change() is able to change
the value of a[0] of main(). It uses Call By Explanation:
Reference. So changes in called function Short array s[5] will take 10 bytes as size of
affected the original values. short is 2 bytes. When we declare a union,
181. C memory allocated for the union is equal to
Explanation: memory needed for the largest member of it,
Incrementing a pointer points to the address of and all members share this same memory
next element. ary points to first element. ary +1 space. Since u is a union, memory allocated to
u will be max of float y(4 bytes) and long z(8
bytes). So, total size will be 18 bytes (10 + 8).
61
207. C makes a copy of the pointer, so when malloc()
Explanation: is called, it is setting the copied pointer to the
When we declare a union, memory allocated memory location, not p. p is pointing to
for a union variable of the type is equal to random memory before and after the call to
memory needed for the largest member of it, fun(), and when you dereference it, it will
and all members share this same memory crash. If you want to add memory to a pointer
space. In above example, "char arr[8]" is the from a function, you need to pass the address
largest member. Therefore size of union test is of the pointer (ie. double pointer).
8 bytes. 215. B
Explanation:
208. C free() can be called for NULL pointer, so no
Explanation: problem with free function call. The problem is
Since fields/members of union share same memory leak, p is allocated some memory
memory, both i1 and i2 refer to same location. which is not freed, but the pointer is assigned
Also, since both i1 and i2 are of same type, as NULL. The correct sequence should be
initializing one would initialize the other as following: free(p); p = NULL;
well implicitly. 216. D
217. C
209. B Explanation: The size of a pointer is 2 bytes
210. A on a 16 bit platform, 4 bytes on a 32 bit
DMA platform and 8 bytes on a 64 bit platform.
211. D 218. B
Explanation: The above code results in an Explanation: An example of memory
error. This is because the syntax of the function allocated using malloc():
calloc() is incorrect. In order to rectify this (int*)malloc(3*sizeof(int)
error, we must write: calloc(3,sizeof(int)); It is clear from the above example that malloc()
212. A takes only one argument as input, that is the
Explanation: If we allocate memory number of bytes to be allocated.
dynamically in an function (malloc, calloc, 219. A
realloc), the allocated memory will not be de- Explanation: If malloc() and calloc() are not
allocated automatically when the control comes type casted, they return a pointer of the type
out of the function. This allocated memory void.
cannot be accessed and hence cannot be used.
This unused inaccessible memory results in 220. C
memory leak. 221. A
213. B Explanation: A NULL pointer is returned
Explanation: There is no error in the above when the memory allocated by malloc
code. The format specifier being %s, address is dynamically is insufficient.
not returned. Hence, welcome is the output. 222. D
214. A 223. D
Explanation: Explanation: fp is a pointer of FILE type and
The program is not valid. Try replacing “int FILE is a structure that store following
*p;” with “int *p = NULL;” and it will try to information about opened file.
dereference a null pointer. This is because fun() 224. C
62
Explanation: It is what is typically termed an 243. A
opaque data type, meaning it's typically Explanation: *head_ref = prev; At the end of
declared as a simple structure, and then while loop, the prev pointer points to the last
internally in the OS libraries the FILE pointer node of original linked list. We need to change
is cast to the actual date-type of the data- *head_ref so that the head pointer now starts
structure that the OS will use access data from pointing to the last node.
a file. A lot of these details are system-specific 244. D
though, so depending on the OS, the definition Explanation: fun() prints alternate nodes of
may differ. the given Linked List, first from head to end,
225. C and then from end to head. If Linked List has
Explanation: The rewind function sets the file even number of nodes, then skips the last node.
position indicator for the stream pointed to by 245. B
stream to the beginning of the file. Explanation: The function rearrange()
226. A exchanges data of every node with its next
Explanation: The file demo.txt will be opened node. It starts exchanging data from the first
in the binary mod node itself.
227. D 246. B
Explanation: Error occurs due to extra Explanation: A new node is added to the head
parameter in call to fclose(). of the list and a node is deleted from the tail
228. B end of the list.
Explanation: It will print only six five 247. A
character Explanation: In the worst case, you have to
229. B traverse through the entire list of n elements.
Explanation: Mode a+ means we can read and 248. B
write on file but when we will write on file it Explanation: Advance the pointers as
will append at the end content and it doesn’t mentioned in ‘b’, check to see if at any given
truncate the content of file. instant of time if the fast pointer points to slow
230. D pointer or if the fast pointer’s ‘next’ points to
231. B the slow pointer. Note that this trick is useful
232. C only if the list is small.
233. B 249. B
234. D Explanation: The function prints fail if the
235. A given element is not found. Note that this
236. B option is inclusive of option d, the list being
237. A empty is one of the cases covered
238. A 250. B
239. B 251. A
240. A 252. B
241. D Explanation:
242. B ----fun1() prints the given Linked List in
Explanation: fun1() prints the given Linked reverse manner. For Linked List 1->2->3->4-
List in reverse manner. >5, fun1() prints 5->4->3->2->1
For Linked List 1->2->3->4->5, fun1() prints
5->4->3->2->1. STACKS
63
253. A 265. A
254. A 266. B
255. B 267. A
256. B 268. B
257. A 269. D
258. A 270. C
259. A 271. A
260. C 272. A
261. D 273. B
262. B 274. C
Explanation: 275. D
The function of the program is:- 1) If the Explanation:
current character is a digit it pushes into stack The function takes a queue Q as an argument.
2) Else if the current character is operator, it It dequeues all items of Q and pushes them to a
pops two elements and then performs the stack S. Then pops all items of S and enqueues
operation. Finally it pushes the resultant the items back to Q. Since stack is LIFO order,
element into stack. Initially stack s is empty. 5 all items of queue are reversed.
2 * 3 3 2 + * + 1) 5 -> It pushes into s 2) 2 -> It 276. B
pushes into s 3) * -> It pops two elements n = 277. C
2, m=5 n*m = 10 It pushes 10 into s 4) 3 -> It Explanation:
pushes into s 5) 3 -> It pushes into s 6) 2 -> It The function prints first n Fibonacci Numbers.
pushes into s 7) + -> n=2, m=3 n+m=5 It Note that 0 and 1 are initially there in q. In
pushes 5 into s 8) * -> n=5, m=3 n*m=15 It every iteration of loop sum of the two queue
pushes 15 into s 9) + -> n=15, m=10 n+m = 25 items is enqueued and the front item is
It pushes 25 into s. Finally the result value is dequeued.
the only element present in stack. This solution 278. D
is contributed by Anil Saikrishna Devarasetty. 279. A
Result = 25 Explanation: Condition for size of queue.
263. D TREES
Explanation: 280. B
When five items: A, B, C, D, and E are pushed 281. A
in a stack: Order of stack becomes: A, B, C, D, 282. A
and E (A at the bottom and E at the top.) stack 283. C
is popped four items and each element is 284. D
inserted in a queue: Order of queue: B, C, D, E 285. A
(B at rear and E at the front) Order of stack 286. A
after pop operations = A. Two elements deleted 287. D
from the queue and pushed back on the stack: 288. B
New order of stack = A, E, D(A at the bottom, 289. A
D at the top) As D is on the top so when pop 290. B
operation occurs D will be popped out. So, 291. C
correct option is (D). 292. A
264. A 293. B
QUEUES 294. C
64
295. D MABCKYFPH will be in order. Since we have
296. C all the traversals identified, let's try to draw the
297. C binary tree if possible.
298. B
Explanation: In postfix form two operands
come together then operator. For example, in
A+B, A and B are two operands and + is one
operator and A+B is in infix form. Hence, in
postfix of A+B will be AB+.
Let’s consider the question above
(A+B) *(C+D)//this expression is in infix form
First get A and B operand together then
operator +. Similarly, for C and D
(AB+) * (CD+)
now consider AB+ and CD+ as two operands.
Take them together then * operator. I. Post order
(AB+) (CD+) * II. Pre order
Remove brackets. III. Inorder
AB+CD+* 303. B
So, AB+CD+* is the postfix expression of 304. C
(A+B) *(C+D) infix expression. 305. B
299. B 306. C
300. A
Explanation: Explanation: In a BST, value (left node) <
Number of nodes of binary tree will be value(root) < value(right node) We can
maximum only when tree is full complete, consider an example to find out the 4th
therefore answer is 2^(i)-1 So, option (A) is smallest element:
true.
301. A
Explanation:
Inorder traversal of a BST always gives
elements in increasing order. Among all four
options, a) is the only increasing order
sequence.
302. D
Explanation:
The approach to solve this question is to first
find 2 sequences whose first and last element is
same. The reason being first element in the Pre-
order of any binary tree is the root and last
element in the Post-order of any binary tree is From the above BST, we can clearly see that 8
the root. Looking at the sequences given, Pre- is the fourth smallest element. So, option (C) is
order = KAMCBYPFH Post-order = correct.
MBCAFHPYK Left-over sequence
65
315. A
307. D Explanation:
308. A Below is the given tree.
309. B a
Explanation: / \
Binary Search is a linear searching algorithm / \
and takes O(log n) when array is sorted. Refer: b c
Binary Search T(n) = T(n / 2) + k , where k is / \ / \
constant produces a complexity of O(log n). / \ / \
310. B d e f g
311. B 316. B
312. B 317. D
Explanation: Explanation: DoSomething() returns
Since the given B tree is 2-3-4 tree, there can max(height of left child + 1, height of left child
be at-most 4 children or 3 keys. In B Tree + 1). So given that pointer to root of tree is
insertion, we start from root and traverse till the passed to DoSomething(), it will return height
leaf node where key is to be inserted. While of the tree. Note that this implementation
traversing, if we find a a node which full, we follows the convention where height of a single
split it. When we insert G, we find root itself is node is 0.
full, so we split it. When we come down to
leftmost leaf, we find that the leaf is also full, 318. A
so we split the leaf also. Explanation:
Algorithm Inorder(tree) - Use of Recursion
313. B Steps:
Explanation: 1. Traverse the left subtree,
We can get all values in range from 7 to 59 by i.e., call Inorder(left-subtree)
accessing 5 nodes. 2. Visit the root.
1) First search 7 in a leaf node. 3. Traverse the right subtree,
2) Once 7 is found, linearly traverse till 15 is i.e., call Inorder(right-subtree)
found. Understanding this algorithm requires the basic
understanding of Recursion
See following diagram Therefore, We begin in the above tree with root
as
the starting point, which is P.
# Step 1( for node P) :
Traverse the left subtree of node or root P.
So we have node Q on left of P.
-> Step 1( for node Q)
314. B Traverse the left subtree of node Q.
Explanation: So we have node S on left of Q.
If a tree is not empty, height of tree is * Step 1 (for node S)
MAX(Height of Left Subtree, Height of Right Now again traverse the left subtree of node S
Subtree) + 1 which is
66
NULL here. (a + (b c x)) − d e f ^ ^
* Step 2(for node S) (a (b c x) +) − d e f ^ ^
Visit the node S, i.e print node S as the 1st (a b c x +) - (d e f ^ ^)
element of (a b c x +) - (d e f ^ ^)
inorder traversal. abcx+def^^-
* Step 3(for node S)
Traverse the right subtree of node S. 320. D
Which is NULL here. Explanation:
Now move up in the tree to Q which is parent As here we want subset of edges that connects
of S.( Recursion, function of Q called for all the vertices and has minimum total weight
function of S). i.e. Minimum Spanning Tree Option A -
Hence we go back to Q. includes cycle, so may or may not connect all
-> Step 2( for node Q): edges. Option B - has no relevance to this
Visit the node Q, i.e print node Q as the 2nd question. Option C - includes cycle, so may or
element of inorder traversal. may not connect all edges.
-> Step 3 (for node Q) 321. B
Traverse the right subtree of node Q. Explanation:
Which is NULL here. 1: abef->c or g should be covered
Now move up in the tree to P which is parent 4: adbc->e or f should be covered
of Q.( Recursion, function of P called for 2: abefcgd correct
function of Q). 3: adgebcf correct
Hence we go back to P. this set of Data Structure Multiple Choice
# Step 2(for node P) Questions & Answers (MCQs) focuses on
Visit the node P, i.e print node S as the 3rd “Graph”.
element of inorder traversal.
# Step 3 (for node P)
Traverse the right subtree of node P.
Node R is at the right of P.
Till now we have printed SQP as the inorder of
the tree.
Similarly other elements can be obtained by
traversing
the right subtree of P.
The final correct order of Inorder traversal
would
be SQPTRWUV.
319. A
Explanation:
The postfix expression:
a + b × c − ( d ^( e ^ f))
a + b × c − ( d ^( e f ^ ))
a + b × c − ( d e f ^ ^)
(a + (b × c)) − d e f ^ ^
67
JAVA
68
JAVA: 2. JAVA
4. What is an Iterator
a) key word b)interface
c)method d)all
69
9. A class can be declared as _______ if you do
not want the class to be subclassed. Using 15. strictfp cannot be applied
the __________keyword we can abstract a a)constructors
class interface from its implementation b) interface methods
a) protected ,interface b) final,interface c)both a,b
c) public,friend d) final,protected d) none
11. Re-implementing an inherited method in a 17. What type of internet technology sends
sub class to perform a different task from the information to you without you requesting
parent class is called that information?
a)F2b2C b) Infoware
a) Binding b) Transferring
c)Push d) Wiki
c) Hiding d) Coupling
e) extending 18. What is the second generation of the Web
called?
12. In Java, declaring a class abstract is useful a) New web b) Emerging space
a) to prevent developers from further extending c) Second life d) Web 2.0
the class
19. What type of web technology allows its
b) When it doesn't make sense to have objects of
community members to continuously change
that class the contents on a web site?
c) w hen default implementations of some a) Intelligent bots b) Social networks
methods are not desirable c) Wiki d) Blog
d) to force developers to extend the class not to
use its capabilities 20. MAIN() method is always
a)PUBLIC b)PRIVATE
e) When it makes sense to have objects of that
c)STATIC d)VOID
class.
21. What type of web technology provides
13. Object oriented inheritance models the news that can automatically download right to
a) is a kind of" relationship your desktop?
b) "has a" relationship a)Social network b)RSS feed
c)want to be" relationship c) Podcast d) Wiki
d) inheritance does not describe any kind of
relationship between classes 22. What type of web technology creates an
e)“contains” of relationship. online community where people can make
statements and others can read and respond to
14. In object oriented programming, new those statements?
classes can be defined by extending existing a)I-Journal b)Podcast
classes. This is an example of: c)ASP d)Blog
a) Encapsulation b) Interface
c) Composition d) Inheritance
e) Aggregation.
70
23. What type of technology allows you to if(x !=10&& x /0==0)
verbally speak with someone over the System.out.println(y);
Internet? else
a)Wiki b)Social network
System.out.println(++y);
c)Ephone d)VoIP
}
24. What kind of environment is Facebook or }
MySpace part of? a) 1
a)Wiki b)Blog b) 2
c)Social networking d)VoIP c) Runtime error owing to division by zero in if
condition.
25. What term refers to living life through
d) Unpredictable behavior of program.
technology?
a)Virtual living b)E-living
c)Virtual space d)E-Society 30. What is the output of this program?
class bitwise_operator
26. What 3-D environment allows you to speak
to someone who is far away but, at the same {
time, see them as a holographic image? public static void main(String args[])
a)CAVE b)Virtual space {
c)E-space d)VoIP int var1 = 42;
int var2 = ~var1;
27. What type of technology allows you to use System.out.print(var1 + " " + var2);
your finger, eye, or voice print to secure your }
information resources? }
a)Haptics b)Caves a) 42 42 b) 43 43
c)Biometrics d)RFID c) 42 -43 d) 42 43
31. What is the output of relational operators?
2.3 OPERATORS a) Integer b) Boolean
c) Characters d) Double
28. Which of these lines of code will give better
performance?
1. a | 4 + c >> b & 7; 2.4 CONDITIONAL STATEMENTS
2. (a | ((( 4 * c ) >> b ) & 7 ))
32. What will be printed as the output of the
a) 1 will give better performance as it has no
following program?
parentheses.
public class testincr
b) 2 will give better performance as it has
{
parentheses.
public static void main(String args[])
c) Both 1 & 2 will give equal performance.
{
d) Dependent on the computer system.
int i = 0;
i = i++ + i;
29. What is the output of this program?
System.out.println("I = " +i);
class Output
}
{
}
publicstaticvoid main(String args[])
a) I = 0 b) I = 1
{
c) I = 2 d) I = 3
int x , y =1;
e) Compile-time Error
x =10;
71
33. What is the output of this program?
class Output 36.What will be the output of the program?
{ public class Switch2
public static void main(String args[]) {
{ final static short x = 2;
int x, y = 1; public static int y = 0;
x = 10; public static void main(String [] args)
if (x != 10 && x / 0 == 0) {
System.out.println(y); for (int z=0; z < 3; z++)
else {
System.out.println(++y); switch (z)
} {
} case x: System.out.print("0 ");
a) 1 case x-1: System.out.print("1 ");
b) 2 case x-2: System.out.print("2 ");
c) Runtime error owing to division by zero in if }}
condition. }}
d) Unpredictable behavior of program. a)0 1 2
b)0 1 2 1 2 2
34.What will be the output of the program? c)2 1 0 1 0 0
int i = l, j = -1; d)2 1 2 0 1 2
switch (i)
{ 37.What will be the output of the program?
case 0, 1: j = 1; /* Line 4 */ public class SwitchTest
{
case 2: j = 2;
public static void main(String[] args)
default: j = 0; {
} System.out.println("value =" + switchIt(4));
System.out.println("j = " + j); }
a) j = -1 b) j = 0 public static int switchIt(int x)
c) j = 1 d) Compilation fails. {
int j = 1;
35.What will be the output of the program? switch (x)
int i = 1, j = 10; {
case l: j++;
do
case 2: j++;
{ case 3: j++;
if(i > j) case 4: j++;
{ case 5: j++;
break; default: j++;
} }
j--; return j + x;
}}
} while (++i < 5); a)value = 2 b)value = 4
System.out.println("i = " + i + " and j = " + j); c)value = 6 d)value = 8
a) i = 6 and j = 5 b) i = 5 and j = 5
c) i = 6 and j = 4 d) i = 5 and j = 6 38.What will be the output of the program?
public class If2
72
{ short hand = 42;
static boolean b1, b2; if ( hand < 50 && !b ) /* Line 7 */
public static void main(String [] args) hand++;
{ if ( hand > 50 ); /* Line 9 */
int x = 0; else if ( hand > 40 )
if ( !b1 ) {
{ hand += 7;
if ( !b2 ) hand++;
b1 = true; }
x++; else
if ( 5 > 6 ) --hand;
{ System.out.println(hand);
x++; }
} }
if ( !b1 ) a)41 b)42
x = x + 10; c)50 d)51
else if ( b2 = true )
x = x + 100; 41.What will be the output of the program?
else if ( b1 | b2 ) public class Test
x = x + 1000; {
}} public static void main(String [] args)
System.out.println(x); {
}} int I = 1;
a)0 b)1 do while ( I < 1 )
c)101 d)111 System.out.print("I is " + I);
while ( I > 1 ) ;
39.What will be the output of the program? }}
public class Switch2 a)I is 1 b)I is 1 I is 1
{ c)No output is produced.
final static short x = 2; d)Compilation error
public static int y = 0;
public static void main(String [] args) 42.What will be the output of the program?
{ int I = 0;
for (int z=0; z < 3; z++) outer:
{ while (true)
switch (z) {
{ I++;
case y: System.out.print("0 "); /* Line 11 */ inner:
case x-1: System.out.print("1 "); /* Line 12 */ for (int j = 0; j < 10; j++)
case x: System.out.print("2 "); /* Line 13 */ {
}}}} I += j;
a)0 1 2 b)0 1 2 1 2 2 if (j == 3)
c)Compilation fails at line 11. continue inner;
d)Compilation fails at line 12. break outer;
}
40.What will be the output of the program? continue outer;
public class If1 }
{ System.out.println(I);
static boolean b; a)1 b)2
public static void main(String [] args) c)3 d)4
{
73
43.What will be the output of the program? c) java.io d) java.lang.reflect
for (int i = 0; i < 4; i += 2)
{ 48. Which of these package is used for
System.out.print(i + " "); handling security related issues in a program?
a) java.security b) java.lang.security
}
c) java.awt.image d) java.io.security
System.out.println(i);
a)0 2 4 b)0 2 4 5 49. Which of these class allows us to get real
c)0 1 2 3 4 d)Compilation fails. time data about private and protected
member of a class?
44.What will be the output of the program? a) java.io
int i = 0, j = 5; b) GetInformation
c) ReflectPermission
tp: for (;;)
d) MembersPermission
{
i++; 50. Which of these package is used for
for (;;) invoking a method remotely?
{ a) java.rmi b) java.awt
if(i > --j) c) java.util d) java.applet
{
51. Which of these package is used for all the
break tp;
text related modifications?
} } a) java.text b) java.awt
System.out.println("i =" + i + ", j = " + j); c) java.lang.text d) java.text.mofify
a)i = 1, j = 0 b)i = 1, j = 4
c)i = 3, j = 4 d)Compilation fails. 52. What is the output of this program?
importjava.lang.reflect.*;
class Additional_packages {
45. What will be the output of the program?
publicstaticvoid main(String args[]){
int I = 0; try{
label: Class c =Class.forName("java.awt.Dimension");
if (I < 2) { Constructor constructors[]= c.getConstructors();
System.out.print("I is " + I); for(int i =0; i < constructors.length; i++)
I++; System.out.println(constructors[i]);
continue label; }
catch(Exception e){
}
System.out.print("Exception");
a)I is 0 b)I is 0 I is 1 }
c)Compilation fails. d)None of the above }
}
2.5 CLASSES AND PACKAGES a) Program prints all the constructors of
‘java.awt.Dimension’ package.
46. Which of these package is used for b) Program prints all the possible constructors of
class ‘Class’.
graphical user interface?
c) Program prints “Exception”
a) java.applet b) java.awt d) Runtime Error
c) java.awt.image d) java.io
53. What is the output of this program?
47. Which of these package is used for importjava.lang.reflect.*;
analyzing code during run-time? class Additional_packages {
a) java.applet b) java.awt publicstaticvoid main(String args[]){
74
try{
Class 2.6 CONSTRUCTORS
=Class.forName("java.awt.Dimension");
Field fields[]= c.getFields(); 56. What is the output of this program?
for(int i =0; i < fields.length; i++) class box {
System.out.println(fields[i]); int width;
} int height;
catch(Exception e){
int length;
System.out.print("Exception");
}}} int volume;
a)Program prints all the constructors of box() {
‘java.awt.Dimension’ package. width = 5;
b) Program prints all the methods of height = 5;
‘java.awt.Dimension’ package. length = 6;
c) Program prints all the data members of }
‘java.awt.Dimension’ package.
void volume() {
d) program prints all the methods and data
member of ‘java.awt.Dimension’ package. volume = width*height*length;
}
54. What is the length of the application box }
made by this program? class constructor_output {
importjava.awt.*; public static void main(String args[])
importjava.applet.*; {
publicclass myapplet extendsApplet{
box obj = new box();
Graphic g;
g.drawString("A Simple Applet",20,20); obj.volume();
} System.out.println(obj.volume);
a)20 b) Default value }
c) Compilation Error d) Runtime Error }
a) 100 b) 150
55. What is the output of this program?
c) 200 d) 250
importjava.lang.reflect.*;
class Additional_packages {
publicstaticvoid main(String args[]){ 57. What is the output of this program?
try{ class equality
Class c =Class.forName("java.awt.Dimension"); {
Method methods[]= c.getMethods(); int x;
for(int i =0; i < methods.length; i++) int y;
System.out.println(methods[i]); boolean isequal()
} {
catch(Exception e){
return(x == y);
System.out.print("Exception");
}}} }
a) Program prints all the constructors of }
‘java.awt.Dimension’ package. class Output {
b) Program prints all the methods of public static void main(String args[])
‘java.awt.Dimension’ package. {
c) Program prints all the data members of equality obj = new equality();
‘java.awt.Dimension’ package.
d) program prints all the methods and data obj.x = 5;
member of ‘java.awt.Dimension’ package. obj.y = 5;
75
System.out.println(obj.isequal); obj.area(5 , 6);
} System.out.println(obj.length + " " + obj.width);
} }}
a) false b) true a) 0 0
c) 0 d) 1 b) 5 6
c) 6 5
58. What is the output of this program? d) 5 5
class box {
int width;
60. What is the expected output?
int height; public class Profile {
int length; private Profile(int w) { // line 1
int volume; System.out.print(w);
void finalize() { }
volume = width*height*length; public static Profile() { // line 5
System.out.print (10);
System.out.println(volume);
}
} public static void main(String args[]) {
protected void volume() { Profile obj = new Profile(50);
volume = width*height*length; }}
System.out.println(volume); a) Won't compile because of line (1), constructor
} can't be private
} b) 10 50
c) 50
class Output {
d) Won't compile because of line (5), constructor
public static void main(String args[]) can't be static
{ e)BOTH A,D
box obj = new box();
obj.volume(); 61.The following code contains one
} compilation error, find it?
} public class Test {
Test() { }
a) 150 b) 200
static void Test() { this(); }
c) Runtime error d) Compilation error
public static void main(String[] args) {
Test();
59. What is the output of this program? } }
class area {
a) At line 1, constructor Tester must be marked
int width; public like its class
int length; b) At line 2, constructor call
int area; c) At line 3, compilation error, ambiguity
void area(int width, int length) { problem, compiler can't determine whether a
this.width = width; constructor
d) At line 4
this.length = length;
} 62. Which of the below code can be insert at
} line 7 to make clean compilation ?
class Output { class A{
public static void main(String args[]) A(String s){}
{ A(){}
area obj = new area(); }
class B extends A{
76
B(){} public class Test{
B(String s){ public static void main(String[] args){
super(s); A a = new B();
} System.out.println(a.f());
void test(){// insert code here }
}} }
a)A a = new B(); a)Compilation Fails
b)A a = new B(5); b)Prints 0
c)A a = new A(String s); c)Prints 10
d)All of the above d)Prints 7
e)None of these e)None of these
63. What is the output for the below code ? 65.Which of the following cannot be marked
class A{ static ?
public A(){ a) Constructors , Classes ( Outer ) , Classes (
System.out.println("A"); nested ), Interfaces , Local variables , Inner Class
} methods and instance variables.
public A(int i){
b) Constructors , Classes ( Outer ) , Interfaces ,
this();
System.out.println(i); Local variables , Class variables , Class Methods
}} , Inner Class methods and instance variables.
class B extends A{ c) Constructors , Classes ( Outer ) , Interfaces ,
public B(){ Local variables , Inner Class methods and
System.out.println("B"); instance variables.
} d) Constructors , Classes ( Outer ) , Classes
public B(int i){
(Nested), Interfaces , Local variables , Inner
this();
System.out.println(i+3); Class methods and instance variables
}}
public class Test{ 2.7 THREADS AND COLLECTIONS
public static void main (String[] args){
new B(5); 66.How will you invoke any external process
}} in Java?
a)A B 8 b)A 5 B 8 a)Runtime.getRuntime().exec(….)
c)A B 5 d)B 8 A 5 b)Runtime.setRuntime().exec(….)
e)None of these c)Runtime.getchRuntime().exec(….)
d)None
64. What will be the result of compiling and
running the given code? 67.Which of these method waits for the thread
class A{ to terminate?
int b=10; a) sleep()
A(int i){ b) isAlive()
this.b=i; c) join()
} d) stop()
int f(){
return b; 68. Which of these method is used to explicitly
} set the priority of a thread?
} a) set()
class B extends A{ b) make()
int b; c) setPriority()
} d) makePriority()
77
}
69.What is synchronization in reference to a publicvoid run(){
thread? System.out.println(t.isAlive());
a) It’s a process of handling situations when two }}
or more threads need access to a shared resource. class multithreaded_programing
b) Its a process by which many thread are able to {
access same shared resource simultaneously. publicstaticvoid main(String args[])
c) Its a process by which a method is able to {
access many different threads simultaneously. new newthread();
d) Its a method that allow to many threads to }}
access any information require. a)0 b) 1
c) true d) false
70.What is the output of this program?
class newthread extendsThread 72. What is the output of this program?
{ class newthread implements Runnable
Thread t; {
newthread() Thread t;
{ newthread(){
t =newThread(this,"My Thread"); t =newThread(this,"My Thread");
t.start(); t.start();
} }}
publicvoid run() class multithreaded_programing
{ {
try{ Public static void main(String args[])
t.join() {
System.out.println(t.getName()); new newthread();
} }}
catch(Exception e) a)My Thread
{ b) Thread[My Thread,5,main]
System.out.print("Exception"); c) Compilation Error
}}} d) Runtime Error
class multithreaded_programing
{ 2.8 EXCEPTION HANDLING
Public static void main(String args[])
{ 73. What is the output of this program?
new newthread(); class exception_handling
} {
} publicstaticvoid main(String args[])
a)My Thread {
b) Thread[My Thread,5,main] Try
c) Exception {
d) Runtime Error int a = args.length;
int b =10/ a;
71. What is the output of this program? System.out.print(a);
class new thread extends Thread Try
{ {
Thread t; if(a ==1)
newthread() a = a / a - a;
{ if(a ==2)
t =newThread(this,"New Thread"); {
t.start(); int c ={1};
78
c[8]=9; public class Test
}} {
catch(ArrayIndexOutOfBoundException e) public static void main(String args[])
{ {
System.out.println("TypeA"); int i;
} try{
catch(ArithmeticException e) i = calculate();
{ System.out.println(i);
System.out.println("TypeB"); }catch(Exception e)
}}}} {
a)TypeA b) TypeB System.out.println("Error occured");
c) 0TypeA d) 0TypeB }}
static int calculate()
74. Which of these methods return localized {
description of an exception? return (7/2);
a) getLocalizedMessage() }}
b) getMessage() a) 3 b)3.5
c) obtainLocalizedMessage() c) Error occurred d) Compilation Error
d) printLocalizedMessage()
75. What will be the output of the following 77. What will be the result after compiling this
piece of code: code?
class Person{ class SuperClass{
public void talk() {} public int doIt(String str, Integer... data)throws
} Exception{
public class Test{ String signature = "(String, Integer[])";
public static void main(String args[]){ System.out.println(str + " " + signature);
Person p = null; return 1;
try{ }
p.talk(); }
} public class Test extends SuperClass{
catch(NullPointerException e){ public int doIt(String str, Integer... data){
System.out.print("There is a String signature = "(String, Integer[])";
NullPointerException. "); System.out.println("Overridden: " + str + " "
} +signature);
catch(Exception e){ return 0;
System.out.print("There is an Exception. "); }
} public static void main(String... args){
System.out.print("Everything went fine. "); SuperClass sb = new Test();
} sb.doIt("hello", 3);
} }}
a) There is a NullPointerException. Everything a) Overridden: hello (String, Integer[])
went fine. b) hello (String, Integer[])
b) There is a NullPointerException. c) Compilation fails
c)There is a NullPointerException. There is an d) None of these
Exception.
d)This code will not compile, because in Java
there are no pointers.
79
JAVA ANSWERS:
DBMS
80
DBMS:
INTRODUCTION 3. DBMS:
81
8.Physical Data Independence is ability to 14. The ______ is the one in which the primary
modify _____________ without causing key of one relation is used as a normal
application program to rewrite. attribute in another relation .
a)Physical Schema a)Referential relation
b)Conceptual Schema b)Referencing relation
c)Logical Schema c)Referenced relation
d)NONE d)Referred Relation
9.Logical Data independence is the ability to 15. A _________ integrity constraint requires
modify ____________ without causing that the values appearing in specified
application program to rewrite. attributes of any tuple in the referencing
a)Physical Schema relation also appear in specified attributes of
b)Logical Schema at least one tuple in the referenced relation.
c)Conceptual Schema a)Referential
d)None of the above b)Referencing
c)Specific
10.Data independence is the type of data d)Primary
transparency that matters for a centralized
DBMS. 16. super key is
a)True a) same as primary key
b)False b) primary key and attribute
c) same as foreign key
3.2 RELATIONAL DBMS d) foreign key and attribute
11. Which one of the following cannot be 17. Which of the following is a procedural
taken as a primary key ? language ?
a)Id b)Register number a) Domain relational calculus
c)Dept_id d)Street b) Tuple relational calculus
c) Relational algebra
12. A attribute in a relation is a foreign key if d) Query language.
the _______ key from one relation is used as
an attribute in that relation. 18. The_____ operation allows the combining
a) Candidate b) Primary of two relations by merging pairs of tuples,
c) Super d) sub one from each relation, into a single tuple.
a)Select b)Join
13. The relation with the attribute which is the c)Union d)Intersection
primary key is referenced in another relation.
The relation which has the attribute as 19. The result which operation contains all
primary key is called ? pairs of tuples from the two relations,
a)Referential relation regardless of whether their attribute values
b)Referencing relation match.
c)Referenced relation a)Join b)Cartesian product
d)Referred Relation c)Intersection d)set Difference
82
26. Which of the following constraint is used
20. a functional dependency XY is to limit the value range that can be placed in a
___________dependency if removal of any column?
attribute A from X means that the dependency a) Check b) Default
does not hold any more c) Unique d) None of the above
a)full functional b) multi valued
c)single valued d)none 27.Dr.E.F. Codd represented________rules
that a database must obey if it has to be
21. The most commonly used operation in considered truly relational.
relational algebra for projecting a set of tuple a) 10 b) 15
from a relation is. c) 14 d) 12
a)Join b)Projection
c)Select d)union 28. In E-R Diagram, weak entity is
represented by___________.
22. The _______ operator takes the results of a) Rectangle b) Square
two queries and returns only rows that appear c) Double Rectangle d) Circle
in both result sets.
a)Union b)Intersect 29. An entity that is related with itself is
c)Difference d)Projection known as____________.
a) binary relationship
23. A ________ is a pictorial depiction of the b) recursive relationship
schema of a database that shows the relations c) ternary relationship
in the database, their attributes, and primary d) None of the above
keys and foreign keys.
a)Schema diagram 30.__________is a bottom-up approach in
b)Relational algebra which two lower level entities combine to form
c)Database diagram a higher level entity.
d)Schema flow a) Aggregation b) Specialization
c) Generalization d) None of the above
24. The _________ provides a set of operations 31. An entity set that does not have sufficient
that take one or more relations as input and attributes to form a primary key, is a ……
return a relation as an output a) Primary entity set b) Weak entity set
a) Schematic representation c) Strong entity set d) None of the above
b)Relational algebra
c)Schema diagram 32. In __________database, data is organized
d)Relational flow in the form of trees with nodes.
a) Hierarchical b) Relational
25 ________ allows a unique number to be c) Network d) None of the above
generated when a new record is inserted into a
table. 3.3 SQL QUERIES
a) Insert Into Select b) Insert Into
c) Select Into d) Auto Increment 33.My_date table:
Birthdate
2015-01-21
2015-01-22
83
2015-01-23 S002
2015-01-24 S003
2015-01-25 S004
2015-01-26
S0012
NULL
2015-01-19 S00
Select * from My_date c)StudentID Name Total_Student_Marks
Where Birthdate like '2014[-]01[.-]%'; S001 Kartik 98
Tell the result of above query: S002 Sunny 83
a)Birthdate S003 Jimmy 75
2014-01-21 S004 Chotu 71
2014-01-22
S00 A Be 100
2014-01-23
2014-01-24 d) None of above
2014-01-25
2014-01-26 35. Consumer table:
2014-01-19 Cust_ID Name City IndustryType
b) NULL 4 Chocolate Pleasant J
c)Birthdate 6 Pastry Oaktown J
d)Birthdate
7 Samosa Jackson B
2015-01-21
2015-01-22 9 Orange Jackson B
2015-01-23 What is the result of below query:
2015-01-24 Select * from Consumer
2015-01-25 Where City like '%%Jackson';
2015-01-26 a)
NULL
Cust_ID Name City IndustryType
2015-01-19
7 Samosa Jackson B
9 Orange Jackson B
34.High_Score table:
StudentID Name Total_Student_Marks
S001 Kartik 98 b) It will throw an error.
S002 Sunny 83 c)
S003 Jimmy 75 Cust_ID Name City IndustryType
S004 Chotu 71 4 Chocolate Pleasant J
S0012 Sunil 99 6 Pastry Oaktown J
S00 A Be 100 7 Samosa Jackson B
What will be the result of below query:
9 Orange Jackson B
Select * from High_Score
d)
WHERE LEFT(StudentID, 3) IN ('S00')
Cust_ID City IndustryType
a)StudentID Name Total_Student_Marks 4 pleasant J
S001 Kartik 98 6 Oaktown J
S002 Sunny 83 7 Jackson B
S003 Jimmy 75 9 Jackson B
S004 Chotu 71
S0012 Sunil 99 36. _____ clause is an additional filter that is
S00 A Be 100 applied to the result
b)StudentID a) Select b) Group-by
S001 c) Having d) Order by
84
c) Tuples with any salary
37. _________ joins are SQL server default d) All of the mentioned
a) Outer b) Inner
c) Equi d) None of the mentioned 44. In a employee table to include the
attributes whose value always have some value
38. The _____________ is essentially used to which of the following constraint must be used
search for patterns in target string. ?
a) Like Predicate b) Null Predicate a) Null b) Not null
c) In Predicate d) Out Predicate c) Unique d) Distinct
39. A _____ indicates an absent value that may 45. Using the ______ clause retains only one
exist but be unknown or that may not exist at copy of such identical tuples.
all. a) Null b) Unique
a) Empty tuple b) New value c)not null d)Distinct
c) Null value d) Old value
46. Create table employee (id integer,name
40. If the attribute phone number is included varchar(20),salary not null);
in the relation all the values need not be Insert into employee values (1005,Rach,0);
entered into the phone number column . This Insert into employee values (1007,Ross, );
type of entry is given as Insert into employee values (1002,Joey,335);
a) 0 b) _ Some of these insert statements will produce an
c) Null d) Empty space error. Identify the statement.
a) Insert into employee values (1005,Rach,0)
41. The predicate in a where clause can b) Insert into employee values(1002,Joey,335)
involve Boolean operations such as and.The c) Insert into employee values (1007,Ross, )
result of true and unknown is_______, false d) Both a and c
and unknown is _____, while unknown and
unknown is _____. 47. The primary key must be
a) Unknown, unknown, false a) Unique b) Not null
b) True, false, unknown c) Both a and b d) Either a or b
c) True, unknown, unknown
d) Unknown, false, unknown 48. You attempt to query the database with
this command: (25)
42. For like predicate, which of the following is select nvl (100 / quantity, none)
true. from inventory;
i) % matches zero of more characters. Why does this statement cause an error when
ii) _ matches exactly one character. QUANTITY values are null?
a) i-only b) ii-only a) expression attempts to divide by a The null
c) Both of them d) None of them value
b) The data types in the conversion function are
43. Select name from instructor where salary incompatible
is not null;Selects c) The character string none should be enclosed
a) Tuples with null value in single quotes (‘ ‘).
b) Tuples with no null values
85
d) A null value used in an expression cannot be a) Select distinct course id from section where
converted to an actual value semester = ’Fall’ and year= 2009 and course id
not in (select course id from section where
49. The result of _____unknown is unknown. semester = ’Spring’ and year= 2010)
a)XOR b)OR b) Select distinct course_id from instructor where
c)AND d)NOT name not in (’Fall’, ’Spring’)
c) (Select course id from section where semester
50. Aggregate functions are functions that = ’Spring’ and year= 2010)
take a ___________ as input and return d) Select count (distinct ID) from takes where
a) Collection of values b) Single value (course id, sec id, semester, year) in (select
c) Aggregate value d) Both a & b course id, sec id, semester, year from teaches
where teaches.ID= 10101)
51. Select __________from instructor where
dept name= ’Comp. Sci.’; 56. We can test for the nonexistence of tuples
Which of the following should be used to find in a subquery by using the _____ construct.
the mean of the salary ? a) Not exist
a) Mean(salary) b) Avg(salary) b) Not exists
c) Sum(salary) d) Count(salary) c)Exists
d)Exist
52. Select count (____ ID) from teaches where
semester = ’Spring’ and year = 2010; 57. Select dept_name, ID, avg (salary)
If we do want to eliminate duplicates, we use from instructor group by dept_name;
the keyword ______in the aggregate This statement is erroneous because
expression a) Avg(salary) should not be selected
a) Distinct b)Count b) Dept_id should not be used in group by claus
c)Avg d)Primary key c) Misplaced group by clause
d) Group by clause is not valid in this query
53. A Boolean data type that can take values
true, false, and________ . 58. SQL applies predicates in the _______
a)1 b)0 clause after groups have been formed, so
c)Null d)unknown aggregate functions may be used.
a) Group by b)with
54. The ____ connective tests for set c)where d)Having
membership, where the set is a collection of
values produced by a select clause. The ____ 59. Aggregate functions can be used in the
connective tests for the absence of set select list or the_______clause of a select
membership. statement or subquery. They cannot be used in
a) Or, in b) Not in, in a ______ clause.
c) In, not in d) In, or a) Where, having b) Having, where
c) Group by, having d) Group by, where
55. Which of the following should be used to
find all the courses taught in the Fall 2009 60. The ________ keyword is used to access
semester but not in the Spring 2010 semester . attributes of preceding tables or subqueries in
the from clause.
86
a)In b)Lateral 67. Which of the following creates temporary
c)Having d)with relation for the query on which it is defined ?
a) With b) From
61. Subqueries cannot c) Where d) Select
a) Use group by or group functions
b) Retrieve data from a table different from the 3.4 JOINS
one in the outer query
c) Join tables 68.___________can be specified in the FROM
d) Appear in select, update, delete, insert clause only.
statements. a)Inner joins b)Outer joins
c)Cross joins d)None of above
62. Which of the following is not a aggregate
function ? 69. The_______________returns a number of
a)Avg b)Sum rows equal to the product of all rows in all the
c)with d)Min tables being joined.
a)Outer join b)Inner join
63. The EXISTS keyword will be true if: c)Cartesian product d)Self Join
a) Any row in the subquery meets the condition
only 70._________return rows only when there is at
b) All rows in the subquery fail the condition least one row from both tables that matches
only. the join condition.
c) Both of these two conditions are met. a)Inner joins b)Outer joins
d) Neither of these two conditions is met. c)Self Join d)Left outer join
64. State true or false.
i) Select operator is not a unary operator. 71.___________return all rows from at least
ii) Project operator chooses subset of attributes or one of the tables or views mentioned in the
columns of a relation. FROM clause, as long as those rows meet any
a) i-True, ii-False WHERE or HAVING search conditions.
b) i-True, ii-True a)Cartesian Product b)Inner Join
c) i-False, ii-True c)Self Join d)Outer joins
d) i-False, ii-False
72.To retain the nonmatching information by
65. …………… database is used as template including nonmatching rows in the results of a
for all databases created. join, use a _________.
a) Master b) Model a)full outer join b)left outer join
c) Tempdb d) None of the above c)right outer join d)Any of above
66. One aspect that has to be dealt with by the 73.________ is simple sql join condition which
integrity subsystem is to ensure that only uses the equal sign as the comparison
valid values can be assigned to each data operator.
items. This is referred to as a)SQL Equi Join b)SQL Non equi join
a) Data Security b) Domain access c)Cross Join d)None of above
c) Data Control d) Domain Integrity
87
74._________is a sql join condition which c) AB->C, C->AD
makes use of some comparison operator other d) A->BCD
than the equal sign like >, <, >=, <= .
a)Cross Join b)SQL Equi Join 81. Consider the above conditions. Which of
c)SQL Non equi join d)None of above. the following relation holds ?
a) Course id-> title, dept name, credits
75.A ___________that does not have a b) Title-> dept name, credits
WHERE clause produces the Cartesian c) Dept name-> credits
product of the tables involved in the join. d) Cannot be determined
a)self join b)cross join
c)outer join d)inner join 82. The algorithm that takes a set of
dependencies and adds one schema at a time,
76.In self join ______ helps the query instead of decomposing the initial schema
processor determine whether columns should repeatedly is
present data from the right or left version of a) BCNF algorithm
the table. b) 2NF algorithm
a)where clause b)from clause c) 3NF synthesis algorithm
c)table alias d)All of above d) 1NF algorithm
77.Which of the following Joins won’t work in 83. The functional dependency can be tested
SQL Server but only supports in Oracle. easily on the materialized view, using the
a)Cross Join b)Equi Join constraints ____________.
c)Self join d)Natural joins a) Primary key b) Null
c) Unique d) Both b and c
3.5 NORMALIZATION
84. Which normal form is considered
78. A relation is in ____________ if an adequate for normal relational database
attribute of a composite key is dependent on design?
an attribute of other composite key. a) 2NF b) 5NF
a) 2NF b) 3NF c) 4NF d) 3NF
c) BCNF d) 1NF
85. Relation R with an associated set of
79. What are the desirable properties of a functional dependencies, F, is decomposed into
decomposition BCNF. The redundancy (arising out of
a) Partition constraint functional dependencies) in the resulting set of
b) Dependency preservation relations is
c) Redundancy a) Zero
d) Security b) More than zero but less than that of an
equivalent 3NF decomposition
80. R (A,B,C,D) is a relation. Which of the c) Proportional to the size of F+
following does not have a lossless join d) Indeterminate
dependency preserving BCNF decomposition.
a) A->B, B->CD 86. A table has fields F1, F2, F3, F4, and F5,
b) A->B, B->C, C->D with the following functional dependencies:
88
F1->F3 F1->F3
F2->F4 F2->F4
(F1,F2)->F5 (F1,F2)->F5
in terms of normalization, this table is in in terms of normalization, this table is in
a) 1NF a) 1NF b) 2NF
b) 2NF c) 3NF d) None of the mentioned
c) 3NF
d) None of the mentioned 91. Let R(A,B,C,D,E,P,G) be a relational
schema in which the following FDs are known
87. Let R(A,B,C,D,E,P,G) be a relational to hold:
schema in which the following FDs are known AB->CD
to hold: DE->P
AB->CD C->E
DE->P P->C
C->E B->G
P->C The relation schema R is
B->G a) in BCNF
The relation schema R is b) in 3NF, but not in BCNF
a) in BCNF c) in 2NF, but not in 3NF
b) in 3NF, but not in BCNF d) not in 2NF
c) in 2NF, but not in 3NF
d) not in 2NF 92. We can use the following three rules to
find logically implied functional dependencies.
88. The functional dependency can be tested This collection of rules is called
easily on the materialized view, using the a) Axioms b) Armstrong’s axioms
constraints ____________. c) Armstrong d) Closure
a) Primary key 93. Which of the following is not a Armstrong’s
b) Null Axiom ?
c) Unique a) Reflexivity rule
d) Both b and c b) Transitivity rule
c) Pseudotransitivity rule
89. Relation R with an associated set of d) Augmentation rule
functional dependencies, F, is decomposed into
BCNF. The redundancy (arising out of 94. The relation employee(ID,name,street,
functional dependencies) in the resulting set of Credit,street,city,salary) is decomposed into
relations is employee1 (ID, name)
a) Zero employee2 (name, street, city, salary)
b) More than zero but less than that of an This type of decomposition is called
equivalent 3NF decomposition a) Lossless decomposition
c) Proportional to the size of F+ b) Lossless-join decomposition
d) Indeterminate c) Both a and b
d) None of the mentioned
90. A table has fields F1, F2, F3, F4, and F5,
with the following functional dependencies:
89
95. Inst_dept (ID, name, salary, dept name, 99) Which statement is true regarding
building, budget) is decomposed into synonyms?
instructor (ID, name, dept name, salary) a) Synonyms can be created for tables but not
department (dept name, views.
building, budget) b) Synonyms are used to reference only those
This comes under tables that are owned by another user.
a) Lossy-join decomposition c) A public synonym and a private synonym can
b) Lossy decomposition exist with the same name for the same table.
c) Lossless-join decomposition d) The DROP SYNONYM statement removes
d) Both a and b the synonym, and the status of the table on which
the synonym has been created becomes invalid.
96. There are two functional dependencies
with the same set of attributes on the left side 100. SCOTT is a user in the database.
of the arrow: Evaluate the commands issued by the DBA:
A->BC 1 – CREATE ROLE mgr;
A->B 2 – GRANT CREATE TABLE, SELECT
This can be combined as ON oe. orders TO mgr;
a) A->BC 3 – GRANT mgr, create table TO SCOTT;
b) A->B Which statement is true regarding the execution
c) B->C of the above commands?
a)Statement 1 would not execute because the
97. Consider a relation R(A,B,C,D,E) with the WITH GRANT option is missing.
following functional dependencies: b)Statement 1 would not execute because the
ABC -> DE and IDENTIFIED BY clause is missing.
D -> AB c)Statement 3 would not execute because role
The number of superkeys of R is: and system privileges cannot be granted together
a) 2 c) 10 in a single GRANT statement.
b) 7 d) 12 d)Statement 2 would not execute because system
privileges and object privileges cannot be granted
together in a single GRANT command.
3.6 TRANSACTION MANAGEMENT
101) OE and SCOTT are the users in the
98.A non-correlated subquery can be defined database. The ORDERS table is owned by OE.
as________ . Evaluate the statements issued by the DBA in
a) A set of sequential queries, all of which must the following sequence:
always return a single value a) SCOTT would be able to query the
b) A set of sequential queries, all of which must OE.ORDERS table.
return values from the same table b) SCOTT would not be able to query the
c) A SELECT statement that can be embedded in OE.ORDERS table.
a clause of another SELECT statement only c) The REVOKE statement would remove the
d) A set of one or more sequential queries in SELECT privilege from SCOTT as well as from
which generally the result of the inner query is the role R1.
used as the search value in the outer query
90
d) The REVOKE statement would give an error You issue the following command to create a
because the SELECT privilege has been granted view that displays the IDs and last names of the
to the role R1
sales staff in the organization:
CREATE OR REPLACE VIEW sales_staff_vu
102) Given below are the SQL statements
AS SELECT employee_id, last_name job_id
executed in a user session:
FROM employees
CREATE TABLE product
WHERE job_id LIKE 'SA_%' WITH CHECK
(pcode NUMBER(2), pnameVARCHAR2(10));
OPTION;
INSERT INTO product VALUES(1, 'pen'); Which statements are true regarding the above
INSERT INTO product VALUES (2,'penci'); view? (Choose all that apply.)
SAVEPOINT a; a)It allows you to insert details of all new staff
into the EMPLOYEES table.
UPDATE product SET pcode = 10 WHERE
b)It allows you to delete the details of the
pcode = 1; existing sales staff from the EMPLOYEES table.
SAVEPOINT b; c)It allows you to update the job ids of the
existing sales staff to any other job id in the
DELETE FROM product WHERE pcode = 2;
EMPLOYEES table.
COMMIT; d)It allows you to insert the IDs, last
DELETE FROM product WHERE pcode=10; CREATE VIEW view_name AS
SELECT column_name(s)
ROLLBACK TO SAVEPOINT a;
FROM table_name
Which statement describes the consequences? WHERE condition.
a)No SQL statement would be rolled back.
b)Both the DELETE statements would be rolled 104) EMPDET is an external table containing
the columns EMPNO and ENAME. Which
back. command would work in relation to the
c)Only the second DELETE statement would be EMPDET table?
rolled back a) UPDATE empdet
SET ename = ‘Amit’
d)Both the DELETE statements and the
WHERE empno = 1234;
UPDATE statement would be rolled back. b) DELETE FROM empdet
WHERE ename LIKE ‘J%’;
c) CREATE VIEW empvu
103) Evaluate the following command:
AS
CREATE TABLE employees (employee_id SELECT* FROM empdept;
NUMBER(2) PRIMARY KEY, last_name d) CREATE INDEX empdet_idx
VARCHAR2(25) NOT ON empdet(empno);
105) The method of access that uses key
NULL, department_id NUMBER(2), job_id transformation is called as
VARCHAR2(8), salary NUMBER(10,2)); a) Direct b) Hash
c) Random d) Sequential
91
3.7 HASHING AND INDEXING attribute values are extremely common, and
other values also occur, but much less
106) The purpose of an N-Ary association is: frequently.
a) To capture a parent-child relationship a) Bitmap, B-tree
b) To deal with one to many relationships b) Bitmap, B+tree
c) To deal with relationships that involve more c) B-tree, Bitmap
than two tables d) B+tree, Bitmap
d) To represent an inheritance relationship
113) In a B+-tree index ______, for each value
107) Bitmap indices are a specialized type of we would normally maintain a list of all
index designed for easy querying on records with that value for the indexed
___________. attribute.
a) Bit values b) Binary digits a) Leaf b) Node
c) Multiple keys d) Single keys c) Root d) Link
108) A _______ on the attribute A of relation r 114) A tablespace is further broken down into
consists of one bitmap for each value that A ________
can take. a) Tablespace b) Segments
a) Bitmap index b) Bitmap c) Extents d) Blocks
c) Index d) Array
115) In ordered indices, the file containing the
109) Select * from r where gender = ’f’ and records is sequentially ordered, a ___________
income level = ’L2’; is an index whose search key also defines the
In this selection, we fetch the bitmaps for sequential order of the file.
gender value f and the bitmap for income level a) Clustered index
value L2, and perform an ________ of the two b) Structured index
bitmaps. c) Unstructured index
a)Union b)Addition d) Nonclustered index
c)Combination d)Intersection
116) Indices whose search key specifies an
110) To identify the deleted records we use the order different from the sequential order of
______________. the file are called ___________ indices.
a) Existence bitmap b) Current bitmap a) Nonclustered
c) Final bitmap d) Deleted bitmap b) Secondary
c) All of the mentioned
111) Bitmaps can be used as a compressed d) None of the mentioned
storage mechanism at the leaf nodes of
________ for those values that occur very 117) What is the purpose of index in sql server
frequently. a) To enhance the query performance
a) B-trees b) B+-trees b) To provide an index to a record
c) Bit trees d) Both a and b c) To perform fast searches
d) All of the mentioned
112) Bitmaps can be combined with regular
B+-tree indices for relations where a few
92
118) How many types of indexes are there in 124) If an index is _________________ the
sql server? metadata and statistics continue to exists
a)1 b)2 a) Disabling b) Dropping
c)3 d)4 c) Altering d) Both a and b
119) How non clustered index point to the 3.8 DEADLOCK AND CONCURRENCY
data? CONTROL
a) It never points to anything
b) It points to a data row 125) In _______________ index instead of
c) It is used for pointing data rows containing key storing all the columns for a record together,
values each column is stored separately with all other
rows in an index.
d) None of the mentioned
a) Clustered
b) Column store
120) Which one is true about clustered index?
c) Non clustered
a) Clustered index is not associated with table
d) Row store
b) Clustered index is built by default on unique
key columns
c) Clustered index is not built on unique key 126) If we wish to grant a privilege and to
allow the recipient to pass the privilege on to
columns
d) None of the mentioned other users, we append the __________ clause
to the appropriate grant
a)With grant
121) What is true about indexes?
a) Indexes enhance the performance even if the b) Grant user
c) Grant pass privilege
table is updated frequently
d) With grant option
b) It makes harder for sql server engines to work
to work on index which have large keys
127) In authorization graph if DBA provides
c) It doesn’t make harder for sql server engines to
work to work on index which have large keys authorization to u1 which inturn gives to u2
d) None of the mentioned which of the following is correct ?
a) If DBA revokes authorization from u1 then
122) Does index take space in the disk ? u2 authorization is also revoked .
b) u1 revokes authorization from u2 then u2
a) It stores memory as and when required
authorization is revoked
b) Yes, Indexes are stored on disk
c) Both a and b
c) Indexes are never stored on disk
d) If u2 revokes authorization then u1
d) Indexes take no space
authorization is revoked
123) What are composite indexes ?
a) Are those which are composed by database for 128) Which of the following is used to avoid
its internal use cascading of authorizations from the user ?
a) Granted by current role
b) A composite index is a combination of index
on 2 or more columns b) Revoke select on department from Amit,
Satoshi restrict;
c) Composite index can never be created
c) Revoke grant option for select on department
d) None of the mentioned
from Amit;
93
d) Revoke select on department from Amit, d) get Count()
Satoshi cascade;
134) Which of the following is a following
129) The granting and revoking of roles by the statement is a prepared statements ?
user may cause some confusions when that a) Insert into department values(?,?,?)
user role is revoked .To overcome the above b) Insert into department values(x,x,x).
situation c) SQLSetConnectOption(conn, SQL
a) The privilege must be granted only by roles AUTOCOMMIT, 0)
b) The privilege is granted by roles and users d) SQLTransact(conn, SQL ROLLBACK)
c) The user role cannot be removed once given
d) By restricting the user access to the roles 135) Constraint checking can be disabled in
existing _______________ and _____________
130) Which of the following is used to access constraints so that any data you modify or add
the database server at time of executing the to the table is not checked against the
program and get the data from the server constraint.
accordingly ? a) CHECK, FOREIGN KEY
a) Embedded SQL b) Dynamic SQL b) DELETE, FOREIGN KEY
c) SQL declarations d) SQL data analysis c) CHECK, PRIMARY KEY
d) PRIMARY KEY, FOREIGN KEY
131) DriverManager.getConnection(_______ ,
______ , ______)What are the two parameters
that are included ? DBMS ANSWERS:
a) URL or machine name where server runs,
1)B 2)B 3)D 4)B 5)D 6) A 7)
Password, User ID
b) URL or machine name where server runs, A 8)A 9)B 10)A 11) D 12)B
User ID, Password
c)User ID, Password, URL or machine name 13)B 14)C 15)A 16)B 17)C 18)B
where server runs
d) Password, URL or machine name where server 19)B 20)A 21)C 22)B 23)A 24)B
runs, User ID
25)D 26)A 27)D 28)C 29)B 30)C
132) Which of the following invokes functions 31)B 32)A 33)A 34)C 35)A 36)C
in sql ?
a) Prepared Statements 37)B 38)A 39)C 40)C 41)D 42)C
b) Connection statement
c) Callable statements 43)B 44)B 45)D 46)C 47)C 48)A
d) All of the mentioned 49)D 50)A 51)B 52)A 53)D 54)C
133) Which of the following function is used to 55)A 56)B 57)B 58)B 59)B 60)B
find the column count of the particular
resultset ? 61)A 62)C 63)C 64)C 65) B 66)D
a) getMetaData()
67)B 68)C 69)A 70)D 71)A 72)A
b) Metadata()
c) getColumn() 73)C 74)B 75)C 76)D 77)B 78)B
94
79)D 80)A 81)82)D 83)D 84)B
135)A
COMPUTER
NETWORKS
95
COMPUTER NETWORKS:
4. COMPUTER NETWORKS
ADDRESSING SYSTEMS
4.1 ADDRESSING SYSTEM
LAN 1. How much channel throughout of slotted
ALOHA will be in comparison to pure
WAN ALOHA.
a) Same b) Double
NETWORKING c) Three times d) None of the above
96
8. How many 8-bit characters can be 13. The maximum size of payload field in
transmitted per second over a 9600 baud ethernet frame is
serial communication link using asynchronous
a) 1000 bytes b) 1200 bytes
mode of transmission with one start bit, eight
data bits, two stop bits, and one parity bit ? c) 1300 bytes d) 1500 bytes
a)600 b)800
c)876 d)1200 14. Mostly ________ is used in wireless LAN.
a) time division multiplexing
9. A 2 km long broadcast LAN has 107 bps b) orthogonal frequency division multiplexing
bandwidth and uses CSMA/CD. The signal c) space division multiplexing
travels along the wire at 2 × 108 m/s. What is d) none of the mentioned
the minimum packet size that can be used on
this network? 4.3 WAN
a)50 bytes b)100 bytes
c)200 bytes d)None of these 15. A default Frame Relay WAN is classified
as what type of physical network?
10. Host A is sending data to host B over a full a)Point-to-point
duplex link. A and B are using the sliding b)Broadcast multi-access
window protocol for flow control. The send c)Non-broadcast multi-access
and receive window sizes are 5 packets each. d)Non-broadcast multipoint
Data packets (sent only from A to B) are all
1000 bytes long and the transmission time for 16. Which of the following describes the
such a packet is 50 µs. Acknowledgement creation of private networks across the
packets (sent only from B to A) are very small Internet, enabling privacy and tunneling of
and require negligible transmission time. The non-TCP/IP protocols?
propagation delay over the link is 200 us. a)HDLC
What is the maximum achievable throughput b)Cable
in this communication? c)VPN
a)7.69 × 106 bytes per second d)IPSec
b)11.11 × 106 bytes per second d)xDSL
c)12.33 × 106 bytes per second
d)15.00 × 106 bytes per second 17. Which command will display the CHAP
authentication process as it occurs between
11. In serial data transmission, every byte of two routers in the network?
data is padded with a ‘0’ in the beginning and a)show chap authentication
one or two ‘I’ s at the end of byte because b)show interface serial 0
c)debug ppp authentication
a) Receiver is to be synchronized for byte d)debug chap authentication
reception
b) Receiver recovers lost ‘0’ and ‘1’s from these 4.4 NETWORKING
padded bits
c) Padded bits are useful in parity computation 18. Multipoint topology is
d) None of these a) Bus b) Star
c) Mesh d) Ring
4.2 LAN
19. In mesh topology, every device has a
dedicated topology of
12. MAC address is of
a) Multipoint linking
a) 24 bits b) 36 bits b) Point to point linking
c) 42 bits d) 48 bits c) None of Above
97
d) Both a and b c) 24 d) 25
20. Bus, ring and star topologies are mostly 4.5 NETWORK LAYER
used in the
a) LAN b) MAN 29. The network layer concerns with
c) WAN d) Internetwork a) bits b) frames
c) packets d) none of the mentioned
21. A local telephone network is an example of
a _______ network 30. Network layer at source is responsible for
a) Packet switched creating a packet from data coming from
b) Circuit switched another
c) both of the mentioned a)Data b)Link
d) none of the mentioned c)IP d)Protocol
98
round of updates, what will be the new distance The round trip time of the connection is 100
vector at node, N3. msec and the maximum segment size used is 2
a)(3, 2, 0, 2, 5) KB. The time taken (in msec) by the TCP
b)(3, 2, 0, 2, 6)
connection to get back to 32 KB congestion
c)(7, 2, 0, 2, 5)
d)(7, 2, 0, 2, 6) window is _________.
a)1100 to 1300 b)800 to 1000
33. For which one of the following reasons c)1400 to 1600 d)1500 to 1700
does Internet Protocol (IP) use the timeto- live
(TTL) field in the IP datagram header 4.7 APPLICATION LAYER
a)Ensure packets reach destination within that
time
39) Which of the following is/are the
b)Discard packets that reach later than that time
c)Prevent packets from looping indefinitely important applications of application layer?
d)Limit the time for which a packet gets queued a) Electronic mail
in intermediate routers. b) World Wide Web
c) USENET
4.6 TRANSPORT LAYER d) All of the above
34. Transport layer aggregates data from 40) The TCP/IP ............. corresponds to the
different applications into a single stream combined session, presentation, and
before passing it to application layers of the OSI model.
a) network layer a)session layer
b) data link layer b) presentation layer
c) application layer c) application layer
d) physical layer d) None of the above
35.The transport layer protocols used for real 41.Consider different activities related to
time multimedia, file transfer, DNS and email, email.
respectively are: m1: Send an email from a mail client to a mail
a)TCP, UDP, UDP and TCP server
b)UDP, TCP, TCP and UDP m2: Download an email from mailbox server
c)UDP, TCP, UDP and TCP to a mail client
d)TCP, UDP, TCP and UDP m3: Checking email in a web browser
Which is the application level protocol used in
36.In the slow start phase of the TCP each activity?
congestion control algorithm, the size of the a)ml: HTTP m2: SMTP m3: POP
congestion window b)ml: SMTP m2: FTP m3: HTTP
a)does not increase c)ml: SMTP m2: POP m3: HTTP
b)increases linearly d)ml: POP m2: SMTP m3: IMAP
c)increases quadratically 42.What is the maximum size of data that the
d)increases exponentially application layer can pass on to the TCP layer
below?
37.Which one of the following uses UDP as the a)Any size
transport protocol? b)216 bytes - size of TCP header
a)HTTP b)Telnet c)216 bytes
c)DNS d)SMTP d)1500 bytes
38.Let the size of congestion window of a TCP 43) ............ is limited to 7-bit ASCII text, with
connection be 32 KB when a timeout occurs. a maximum line length of 1000 characters.
99
a) SMTP b) MIME
c) POP d) MTA
OPERATING
SYSTEMS
100
OPERATING SYSTEMS: 5. OPERATING SYSTEM
101
b) API c) Token Passing
c) library d) Message slots
d) assembly instructions
15. The technique in which the CPU generates
8. One that is not a type of user interface of physical addresses directly is known as :
operating system is a) relocation register method
a)command line interface b) real addressing
b)graphical user interface c) virtual addressing
c)batch interface d) None of these
d)device interface
5.3 SERVICES
5.2 TYPES
16. A ____ a set of wires and a rigidly defined
9. Which one of the following is not a real time protocol that specifies a set of messages that
operating system?
can be sent on the wires.
a) VxWorks b) Windows CE
c) RTLinux d) Palm OS a) port
b) node
10. If one site fails in distributed system c) bus
a) the remaining sites can continue operating d) None of these
b) all the sites will stop working
c) directly connected sites will stop working 17. Global table implementation of matrix
d) none of the mentioned
table contains
11. What is not a major reason for building a) domain
distributed systems ? b) object
a) Resource sharing c) right-set
b) Computation speedup d) all of the mentioned
c) Reliability
d) Simplicity 18. Which principle states that programs,
users and even the systems be given just
12. Preemptive, priority based scheduling
guarantees : enough privileges to perform their task?
a) hard real time functionality a) principle of operating system
b) soft real time functionality b) principle of least privilege
c) protection of memory c) principle of process scheduling
d) None of these d) none of the mentioned
13. What are characteristics of processor in
19. One that is not a service provided by
distributed system ?
operating system of computer is
a) They vary in size and function
a) networking
b) They are same in size and function b) user interface
c) They are manufactured with single purpose
c) program execution
d) They are real-time devices
d) error detection
14. How collisions cannot be avoided in
20. The pattern that can be used to identify a
network ?
virus is known as
a) Carrier sense with multiple access
a) stealth
(CSMA); collision detection (CD)
b) virus signature
b) Carrier sense multiple access with collision
c) armoured
avoidance
102
d) multipartite
27. The address of the next instruction to be
21. What is a trap door in a program? executed by the current process is provided by
a) a security hole, inserted at programming time the
in the system for later use a) CPU registers b) program counter
b) a type of antivirus c) process stack d) pipe
c) security hole in a network
d) none of the mentioned 28. What is interprocess communication?
a) communication within the process
22. Which one of the following is not an b) communication between two process
attack, but a search for vulnerabilities to c) communication between two threads of same
attack? process
a) denial of service d) none of the mentioned
b) port scanning
c) memory access violation 29.For communication operating system of
d) dumpster diving computer system moves
a)processes b) packets
23. File virus attaches itself to the c) programs d) both a and b
a) source file
b) object file 30. With multiprogramming, ______ is used
c) executable file productively.
d) all of the mentioned a) time b) space
c) money d) All of these
24. In asymmetric encryption 31. If a process fails, most operating system write
a) same key is used for encryption and decryption the error information to a
b) different keys are used encryption and a) log file b) another running process
c) new file d) none of the mentioned
decryption
c) no key is required for encryption and 32. DMA is used for : (choose two)
decryption a) High speed devices(disks and communications
d) none of the mentioned network)
b) Low speed devices
25. What is the drawback of banker’s c) Saving CPU cycles
algorithm? d) Utilizing CPU cycles
a) in advance processes rarely know that how
33. A process is selected from the ______
much resource they will need queue by the ________ scheduler, to be
b) the number of processes changes as time executed.
progresses a) blocked, short term b) wait, long term
c) resource once available can disappear c) ready, short term d) ready, long term
d) all of the mentioned
34. Suppose that a process is in “Blocked”
state waiting for some I/O service. When the
26. What is Domain ?
service is completed, it goes to the :
a) Domain = Set of all objects a) Running state b) Ready state
b) It is a collection of protection policies c) Suspended state d) Terminated state
c) Domain= set of access-rights
d) None of these 35. In operating system, each process has its own
a) address space and global variables
b) open files
5.4 PROCESS
c) pending alarms, signals and signal handlers
103
d) all of the mentioned 42. Which does not perform the operations
related to queues for processes ?
36. In indirect communication between a) Job Queue b) PCB queue
processes P and Q : c) Device Queue d) Ready Queue
a) there is another process R to handle and pass
on the messages between P and Q 43. Saving of the suspended process is said to
b) there is another machine between the two be
processes to help communication a) rolled out b) swapped out
c) there is a mailbox to help communication c) both a & b d) None of the above
between P and Q
d) None of these 44. ___________ = __________+____________
a) Turnaround time, Waiting time, Response time
37. A process is selected from the ______ b) Waiting time, Turnaround time, Response time
queue by the ________ scheduler, to be c) Response time, Waiting time, Turnaround time
executed. d) Waiting time, Turnaround time, Processing
a) blocked, short term time
b) wait, long term
c) ready, short term 5.6 SCHEDULING ALGORITHMS
d) ready, long term
45. Which of the policies are used by os to
38. An IPC facility provides atleast two manage each queue
operations : (choose two) a) FIFO
a) write message b) delete message b) Round Robin
c) send message d) receive message c) Priority
d) all of the above
39.In the non blocking send :
a) the sending process keeps sending until the 46. Round robin scheduling falls under the
message is received category of :
b) the sending process sends the message and a) Non preemptive scheduling
resumes operation b) Preemptive scheduling
c) the sending process keeps sending until it c) None of these
receives a message
d) None of these 47. An SJF algorithm is simply a priority
algorithm where the priority is :
5.5 PROCESS SCHEDULING a) the predicted next CPU burst
b) the inverse of the predicted next CPU burst
40. The ________ module gives control of the c) the current CPU burst
CPU to the process selected by the short-term d) anything the user wants
scheduler?
a) dispatcher 48. The FIFO algorithm :
b) interrupt a) first executes the job that came in last in the
c) scheduler queue
d) none of the mentioned b) first executes the job that came in first in the
queue
41. ______ is a part of Time sharing systems. c) first executes the job that needs minimal
a) Long-term scheduler processor
d) Short-term scheduler d) first executes the job that has maximum
c) Medium-term scheduler processor needs
d) None of the above
49. The FIFO algorithm :
104
a) first executes the job that came in last in the a) other threads in the another process can also
queue read from that file
b) first executes the job that came in first in the b) other threads in the same process can also read
queue from that file
c) first executes the job that needs minimal c) any other thread can not read from that file
processor d) all of the mentioned
d) first executes the job that has maximum
processor needs 55. The kernel is _______ of user threads.
a) a part of
50. The real difficulty with SJF in short term b) the creator of
scheduling is : c) unaware of
a) it is too good an algorithm d) aware of
b) knowing the length of the next CPU request
c) it is too complex to understand 56. If the kernel is single threaded, then any
d) None of these user level thread performing a blocking
system call will :
51. In multilevel feedback scheduling a) cause the entire process to run along with the
algorithm: other threads
a) a process can move to a different classified b) cause the thread to block with the other
ready queue threads running
b) classification of ready queue is permanent c) cause the entire process to block even if the
c) processes are not classified into groups other threads are available to run
d) none of the mentioned d) None of these
53. In round robin scheduling, if there are 3 58. The time required to create a new thread
processes p1, p2 and p3 which requires the in an existing process is
following CPU time with a time slice of 5 units a) greater than the time required to create a new
of time. process
time Process Burst time/ Execution b) less than the time required to create a new
P1 P1 20 process
P2 10 c) equal to the time required to create a new
P3 5 process
P1 P2 P3 P1 P2 P1 d) none of the mentioned
P1
P1 P1 P1 P1 P2 P2 59. A thread shares its resources(like data
P1 section, code section, open files, signals) with :
P1 P2 P3 P1 P1 P2 a) other process similar to the one that the thread
P1 belongs to
P1 P2 P3 P1 P1 P1 b) other threads that belong to similar processes
P2 c) other threads that belong to the same process
d) All of these
5.7 MULTI THREADING
60. When one thread immediately terminates
54. If one thread opens a file with read the target thread, it is called :
privileges then a) Asynchronous cancellation
105
b) Systematic cancellation 67. Every address generated by the CPU is
c) Sudden Termination divided into two parts : (choose two)
d) Deferred cancellation a) frame bit
b) page number
61. When the target thread periodically checks c) page offset
if it should terminate and terminates itself in d) frame offset
an orderly manner, it is called :
a) Asynchronous cancellation 68. For every process there is a __________.
b) Systematic cancellation a) page table
c) Sudden Termination b) copy of page table
d) Deferred cancellation c) pointer to page table
d) All of these
5.8 MEMORY MANAGEMENT
69. If the process can be moved during its
62. Address Binding is : execution from one memory segment to
a) going to an address in memory another, then binding must be :
b) locating an address with the help of another a) delayed until run time
address b) preponed to compile time
c) binding two addresses together to form a new c) preponed to load time
address in a different memory space d) None of these
d) a mapping from one address space to another
70. The idea of overlays is to : (choose all that
63. Binding of instructions and data to apply)
memory addresses can be done at : a) enable multiple processes execute at once
a) Compile time b) enable a process to be larger than the amount
b) Load time of memory allocated to it
c) Execution time c) keep in memory only those instructions and
d) All of these data that are needed at any given time
d) All of these
64. The base register is also known as the :
a) basic register 71. When the memory allocated to a process is
b) regular register slightly larger than the process, then :
c) relocation register a) internal fragmentation occurs
d) delocation register b) external fragmentation occurs
c) both a and b
65. What is compaction? d) neither a nor b
a) a technique for overcoming internal
fragmentation 72. The size of a page is typically :
b) a paging technique a) varied
c) a technique for overcoming external b) power of 2
fragmentation c) power of 4
d) a technique for overcoming fatal error d) None of these
66. The operating system is : 73. The operating system maintains a ______
a) in the low memory table that keeps track of how many frames
b) in the high memory have been allocated, how many are there, and
c) either a or b (depending on the location of how many are available.
interrupt vector) a) page
d) None of these b) mapping
c) frame
d) memory
106
1)D 2)B 3)B 4)D 5)D 6)A 7)A
74. In a paged memory, the page hit ratio is
0.35. The required to access a page in 8)D 9)D 10)A 11)D 12)B 13)A
secondary memory is equal to 100 ns. The
time required to access a page in 14)C 15)B 16)C 17)D 18)B
primary memory is 10 ns. The average time
required to access a page is : 19)A 20)B 21)A 22)B 23)C 24)B 25)D
a) 3.0 ns
b) 68.0 ns 26)C 27)B 28)B 29)B 30)A 31)A
c) 68.5 ns
d) 78.5 ns 32) A & C 33)C 34)B 35)D 36)C
75. To obtain better memory utilization, 37)C 38)C & D 39)B 40)A
dynamic loading is used. With dynamic
loading, a routine is not loaded until it is 41)C 42)B 43)B 44)D 45)D 46)B 47)A
called. For implementing dynamic loading,
a) special support from hardware is required 48)B 49)B 50)B 51)A 52)B 53)A
b) special support from operating system is
essential 54)B 55)C 56)C 57)C 58)B 59)C
c) special support from both hardware and
operating system is essential 60)A 61)D 62)D 63)D 64)C 65)C
d) user programs can implement dynamic loading
without any special support from hardware or 66)C 67)B AND C 68)A 69)A 70)B
operating system
AND C 71)A 72)B 73)C 74)C 75)D
76. Consider a computer with 8 Mbytes of
main memory and a 128 K cache. The cache 76)C 77)C
block size is 4 K. It uses a direct mapping
scheme for cache management. How many
different main memory blocks can map onto a
given physical cache block ?
a) 2048
b) 256
c) 64
d) 8
107
108