0 ratings0% found this document useful (0 votes) 44 views5 pagesProgramming Data Structures Obj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
POSTAL
Book Package
Computer Science & IT
Objective Practice Sets
Programming and Data Structures Contents
SI. Topic Page No.
1. Programming Methodology 2
2. Arrays a4
3. Stack 40
4. Queue. 54
5. Linked Lists 63
6. Trees 76
7. Hashing Techniques 97erie Re eee
Programming Methodology
Tras
‘Multiple Choice Questions & NAT Questions
Consider the following function declaration
Aint *)
Which of the following is correct about the
declaration?
(@) fis a function which takes integer pointer as
argument and returns integer.
(b) fis a function which takes integer pointer as
an argument and returns address of an
integer.
(6) fis apointer to a function which takes integer
pointer as an argument and returns integer.
(@) fis a pointer to a function which takes integer
pointer as an argument and returns address
of an integer.
Find the output of the following program:
main()
{
exter inti
20;
pirntf("%d", i)
(@) Linkererror —_(b) 20
(c) Compiler error (d) None of these
Consider the following code?
void main( )
{static int i= 5.
it(--i)
{
main ( )
printf ("6d",
}
}
How many zero’s are printed in the output?
Which of the following is correct output for the
program code given below?
main()
{
void pr);
pr ();
pr ())
pr ();
}
void pr()
{
stalic int i= 1;
printf (*%60", (65+ 1++)):
}
(@) 66,67,68 —(b) 66, 66, 66
(©) 67,6869 (d) None of these
Which of the following are equivalent to the
statement?
int k= (F<< 3) + (>> 2)
(@) int k= i+ 8 + 4
(b) intk=ie34jo
(c) intk=ie 3+ j/2
(d) int k = i/8 + j* 4;
Consider the following foo function and identity
the return value of foo function.
int fo0 (unsigned int 2)
{ intex=
while (nl = 0)
( if(n& t)xse
1
n>>
}
return ¢;
(a) It counts the total number of bits set in an
unsigned integer.
(b) It counts the number of bits which are zero,
(c) Itcounts the number of occurrences of 01
(d) Itreturns the same value as ‘rMADE EASY
7. Consider the following code:
10
int (int a, int b)
{
if(b
else if (b % 2
{
0) return 1
0)
return (f(a, b/2) Ma, b/2))
else
{
}
return (a+ fa, b/2) + fla, bI2));
The return value of (2, 10) is
8. Whatiis output of the following program?
#include
# define R 10
# define C20
int main()
{
}
@
(C)
int(*P) [A] [Ch
printi("%6d'", size of (*P))
getchar( )
return 0;
4 (b) 8
2 (d) None of these
9. Match List-I with List-II
1.
2.
3.
Co
(@)
(b) 2
() 2
()
List-1
typedet int (« ptt) (); ptr p;
int (* P) [4];
int * Pi4l;
List-II
Pointer to an array of integer
WW.
Pointer to a function returning an integer
Array of pointers, pointing to integer
des:
A
vaeoe
2023
Programming & Data Structures
Objective Practice Sets
Consider the folowing pseudocode program
inti
main ()
(
i=3
si)
RO)
}
void § ()
(
print i // prints the value of i on the current
line of output
print ** // prints a blank space on the current
line of output
}
void F()
{
inti
in2
s0)
}
What is the output of the program if the
pseudocode uses either static (exical) scoping
or dynamic scoping?
Static Scoping Dynamic Scoping
(a) 32 32
(b) 33 22
© 33 23
@ 33 32
Consider the following code:
inta=32,b=2,¢
‘Switch (X),
{
Case 2: printi("%d", a);
Case 4: printf(“%a", b);
Case 6: break:
Case 8: printi(“%a", );
default: print(“%a", B);
}
Find the missing statement X, if the above 'C’
code prints the output as 32,
(@ bee (0) bee-2
(9) beor2 (a) None of these18
Computer Science &
Information Technology
EXEEESY Programming Methodology
1
10.
19.
28.
37.
45.
54.
63.
72.
81.
89,
98.
6 2 @ 3 @ 4 @ &
@ 14. @ 12 @ 13% @ 14.
(@) 20. (21) 21. @) 22. @ 23.
(@) 29. (@) 30. (@) 31. (b) 32.
(@) 38. (0) 39. (60) 40. (115) 41.
(2) 46. (c) 47, (@) 48. (b) 49.
(@) 55. (c) 56. (d) 57. (65) 58.
(2) 64. (c) 65. (166) 66. (c) 67.
(61) 73. (23) 74. (c) 75. (61) 76.
() 82. (60) 83. (c) 84. (656) 85.
(@) 90. (106) 91. (a) 92. (17) 93,
(abc) 99. (a,c) 100. (b)
Programming Methodology
+ (b)
The correct declaration for (a) is int f(int »)
The correct declaration for (b) is int* flint“);
The correct declaration for (c) is int (+f) {int =)
The correct declaration for (d) is int «(+f) (int +)
(a)
Linker error: Undefined symbol-7
Extern int i; Specifies to the compiler that the
memory for iis allocated in some other program
and that address will be given to the current
program at the time of linking. But linker finds
that no other variable of name ‘7’ is available in
any other program with memory space allocaled
for it, Hence linker error occurred,
4)
The variable ‘i is declared as static, hence
memory for ‘’ willbe allocated for only once, as it
encounters the statement. The function main) will
be called recursively unless i becomes equal to
zero and since main ( is recursively called, so
the value of static i, i@. 0 will be printed every
time the controls retumed.
So total 4 times zero is printed
2023
MADE EASY
@ 6 (@ 7. (1024 8 @ 9 tb)
(©) 15.) 16 @) 17. &) 18. @
(240) 24. (9) 25. ©) 26. ©) 27. (©)
(2) 33. (114) 84.) 85. 60) 36. (10)
(43211234) 42, (c) 43. (a) 44. (0)
() 50. (©) 51. (©) 52 (©) 53. (b)
(13) 59. (@) 60. (40) 61.) 62. (@)
(6) 68. (290) 69. (1365) 70. (10) 71. (@)
(@) 77. (0) 78. (15) 79. (0) 80. (300)
(@) 86. (>) 87. (@) 88. (302011)
(b) 94 (0) 95. (@) 96. (b) 97. id)
- (d)
The correct output is “BCD" when the function pr
() is first called the value of i is initialized to 1
After the pr () completes its execution i = 2 is
retained for its next call as "i is static variable,
65 +1 = 66(B)
65 +2 = 67(C)
65 + 8 = 68(0)
BCDis the correct output
- (a)
<< and >> are bit wise operators used to multiply
and divide by power of 2 respectively (shitt
operators)
jcc3ie8
jr>2aji4
. (a)
It counts the number of bits set in an unsigned
imeger.
while (nl = 0)
{
if (n&1) x4
[* performs bit wise AND operator and it
conaiition is satisfied if result
contains aileast one 1MADE EASY 023 er oiicctvepractcesers | 19
nosat 12. (c)
} Return statement can contain an expression.
"r++; Maintains the count for number of 1s 13. @)
n>>=1 Shift the ‘bit number by 1 bitto right
7. (1024) ifs AQ ic
2, 10) returns 2"° value = 1024 maint) f Prints: 3 main)
2,10) i=3; m4
—A_ AO BO “4
2.8) * 12,5) ay 1 wg Peat: | 80
ZN o
2+ 2,2) 2,2) a0
Output printed by the code: 3,3
Weta |=2 +2
ZN_ 14. (e)
Beted x Only constants or enurns can be used with cases
of switch. 2+4 is a const expression,
8 (a) 15. (a)
int (+) [F] [C] = pointer to an array of array of Let string gate be stored from memory location
integer. 1000,
Output: 10 * 20 * size of (int) which is 800 for
compliers with integer size as 4 bytes and 400 for cheratray wy ; - rs 8 So) ll characer
compilers with integer size as 2 bytes. bier] Tam Ton sao Tom "Frost ond
The pointer pis de-referenced, hence it yields type
ofthe object. In the present case, itis an array of Given loop prints string from A[0] to ALS}, be
array of integers. ‘gate’
So, it prints R* C* sizeof in) 16. (6)
ow Size of () retums length of sting including null
character (\*). While strlen () returns length of string
A: retum type is int. It is a pointer to a function. , .
without including nll character.
B: (* P} declares pointer. (* P) [4] is array pointed So hore oulputis X= 9, Y=8.
by pointer
C:* P[4] declares array of pointers. 17. (b)
10. (@) Aer Executon
Using static scoping: First print prints the global elelelta
iwhose value is 3. Second print prints the global 5 | 6
iwhose value is 3. 5 | 6 | S| —
Using dynamic scoping: First print prints the 20 | 6 | &a | &
global i whose value is 3. Second print prints the 20 | 20 | &a | &
local i whose value is 2 (from the function it was 20 | 20 | & | &
called). 20 | 30 | &b | &p
41. (ce)
Xibeox2is®
Case 8: prints 3 then default case prints 2
Output prints 32.