You are on page 1of 176

Table of Contents

Data Structures Aptitude........................................................................................2 C Aptitude ............................................................................................................11 C++ Aptitude and OOPS......................................................................................75 Quantitative Aptitude..........................................................................................104 UNI C!ncepts...................................................................................................122 "D#$S C!ncepts...............................................................................................1%& SQ'.....................................................................................................................154 C!(puter Net)!r*s............................................................................................1&2 Operatin+ S,ste(s..............................................................................................170

Unix-121

Data Structures Aptitude Data Structures Aptitude


1. What is data structure? A data structure is a way of organizing data that considers not only the items stored, but also their relationship to each other. Advance knowledge about the relationship between data items allows designing of efficient algorithms for the manipulation of data. 2. List out the areas in which data structures are applied extensively? Compiler Design, Operating System, Database anagement System, Statistical analysis package, !umerical Analysis, "raphics, Artificial #ntelligence, Simulation

3. What are the major data structures used in the following areas : !"#$% &etwor' data model ( )ierarchical data model. $D% S & Array 'i.e. Array of structures( !etwork data model & "raph )ierarchical data model & *rees *. +f you are using , language to implement the heterogeneous lin'ed list% what pointer type will you use? *he heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect them. #t is not possible to use ordinary pointers for this. So we go for void pointer. +oid pointer is capable of storing pointer to any type as it is a generic pointer type. -. #inimum num.er of /ueues needed to implement the priority /ueue? *wo. One ,ueue is used for actual storing of data and another for storing priorities. 0. What is the data structures used to perform recursion?
-

Stack. %ecause of its .#/O '.ast #n /irst Out( property it remembers its 0caller1 so knows whom to return when the function has to return. $ecursion makes use of system stack for storing the return addresses of the function calls. 1very recursive function has its e/uivalent iterative 2non3recursive4 function. 2ven when such e,uivalent iterative procedures are written, e3plicit stack is to be used. 5. What are the notations used in 1valuation of 6rithmetic 1xpressions using prefix and postfix forms? 4olish and $everse 4olish notations. 7. ,onvert the expression 226 8 "4 9 , : 2! : 14 ; 2< 8 =44 to e/uivalent >refix and >ostfix notations. 4refi3 !otation5 6 7 8 9A%C 7 D2 9 /" 4ostfi3 !otation5 A% 9 C 8 D2 7 7 /" 9 6 ?. $orting is not possi.le .y using which of the following methods? 2a4 +nsertion 2.4 $election 2c4 1xchange 2d4 !eletion 'd( Deletion. :sing insertion we can perform insertion sort, using selection we can perform selection sort, using e3change we can perform the bubble sort 'and other similar sorting methods(. %ut no sorting method can be done ;ust using deletion. 1@. 6 .inary tree with 2@ nodes has null .ranches? -< .et us take a tree with = nodes 'n>=(

!ull %ranches

#t will have only ? 'ie,=9<( null branches. #n general, 6 .inary tree with n nodes has exactly n+1 null nodes.

11. What are the methods availa.le in storing se/uential files ? Straight merging, !atural merging, 4olyphase sort, Distribution of #nitial runs. 12. )ow many different trees are possi.le with 1@ nodes ? <A<B /or e3ample, consider a tree with @ nodes'n>@(, it will have the ma3imum combination of = different 'ie, -@ 7 @ > =( trees.

ii

iii

iv

#n general5 +f there are n nodes% there exist 2n-n different trees. 13. List out few of the 6pplication of tree data3structure? *he manipulation of Arithmetic e3pression, Symbol *able construction, Synta3 analysis. 1*. List out few of the applications that ma'e use of #ultilin'ed $tructures? Sparse matri3, #nde3 generation. 1-. +n tree construction which is the suita.le efficient data structure? 2a4 6rray 2.4 Lin'ed list 2c4 $tac' 2d4 Aueue 2e4 none 'b( .inked list 10. What is the type of the algorithm used in solving the 7 Aueens pro.lem? %acktracking 15. +n an 6BL tree% at what condition the .alancing is to .e done? #f the 0pivotal value1 'or the 0)eight factor1( is greater than < or less than &<.

17. What is the .uc'et siCe% when the overlapping and collision occur at same time? One. #f there is only one entry possible in the bucket, when the collision occurs, there is no way to accommodate the colliding value. *his results in the overlapping of values. 1?. Draverse the given tree using +norder% >reorder and >ostorder traversals. "iven tree5
A

"

#norder 5 D ) % 2 A / C # " C 4reorder5 A % D ) 2 C / " # C 4ostorder5 ) D 2 % / # C " C A 2@. Dhere are 7% 1-% 13% 1* nodes were there in * different trees. Which of them could have formed a full .inary tree? <=. #n general5 Dhere are 2n-1 nodes in a full .inary tree. "y the method of elimination: /ull binary trees contain odd number of nodes. So there cannot be full binary trees with D or <B nodes, so re;ected. Eith <@ nodes you can form a complete binary tree but not a full binary tree. So the correct answer is <=. N!te: /ull and Complete binary trees are different. 6ll full .inary trees are complete .inary trees .ut not vice versa. < 21. +n the given .inary tree% using array you can store the node * at which location? @

B =

At location ? < $oot .C< @ $C< 7 .C7 $CB .C@ 7 $C@ 7 .CB = $CB

where .Cn means .eft Child of node n and $Cn means $ight Child of node n 22. $ort the given values using Auic' $ort? ?= FA F= DA D= ?A == =A B=

Sorting takes place from the pivot value, which is the first value of the given elements, this is marked bold. *he values at the left pointer and right pointer are indicated using . and $ respectively. 65 FA. F= DA D= ?A == =A B=$

Since pivot is not yet changed the same process is continued after interchanging the values at . and $ positions 65 65 65 65 B= B= B= B= F= . =A =A =A DA DA . == == D= D= D= . ?A $ ?A ?A ?A $ D= . == == $ DA DA =A $ F= F= F= FA FA FA FA

Ehen the . and $ pointers cross each other the pivot value is interchanged with the value at right pointer. #f the pivot is changed it means that the pivot has occupied its original position in the sorted order 'shown in bold italics( and hence two different arrays are formed, one from start of the original array to the pivot position7< and the other from pivot position9< to end. 60 . 55 . 50 . B= B= B= $ =A =A $ 55 == $ &0 &0 &5 &5 &5 85 . 70 $ 70 DA DA . DA . F= F= F= $ FA $ .5 .5

#n the ne3t pass we get the sorted form of the array.


?

45

50

55

&0

&5

70

75

.0

.5

23. <or the given graph% draw the !<$ and "<$?

*he given graph5

G "
"<$: !<$: AG")42 AG)42H

) 2 4
HC C"

H C

2*. ,lassify the )ashing <unctions .ased on the various methods .y which the 'ey value is found. Direct method, Subtraction method, odulo7Division method, Digit723traction method, id7S,uare method, /olding method, 4seudo7random method. 2-. What are the types of ,ollision esolution Dechni/ues and the methods used in each of the type? Open addressing 'closed hashing(, *he methods used include5 Overflow block, Closed addressing 'open hashing( *he methods used include5 .inked list, %inary treeI 20. +n !"#$% what is the efficient data structure used in the internal storage representation? %9 tree. %ecause in %9 tree, all the data is stored only in leaf nodes, that makes searching easier. *his corresponds to the records that shall be stored in leaf nodes.
F

25. !raw the "3tree of order 3 created .y inserting the following data arriving in se/uence : ?2 2* 0 5 11 7 22 * - 10 1? 2@ 57
<<

<J

-B

<?

-A

--

FD

J-

27.Ef the following tree structure% which is% efficient considering space and time complexities?
2a4 +ncomplete "inary Dree 2.4 ,omplete "inary Dree 2c4 <ull "inary Dree 'b( Complete %inary *ree. "y the method of elimination: /ull binary tree loses its nature when operations of insertions and deletions are done. /or incomplete binary trees, e3tra storage is re,uired and overhead of !:.. node checking takes place. So complete binary tree is the better one since the property of complete binary tree is maintained even after operations like additions and deletions are done on it. 2?. What is a spanning Dree? A spanning tree is a tree associated with a network. All the nodes of the graph appear on the tree once. A minimum spanning tree is a spanning tree organized so that the total edge weight between nodes is minimized. 3@. !oes the minimum spanning tree of a graph give the shortest distance .etween any 2 specified nodes? !o. inimal spanning tree assures that the total weight of the tree is kept at its minimum. %ut it doesnFt mean that the distance between any two nodes involved in the minimum7spanning tree is minimum. 31. ,onvert the given graph with weighted edges to minimal spanning tree.

<
B<A

?AA

?<-JD=

@
@<A

-AA

=
BAA

<B-<

the e,uivalent minimal spanning tree is5 <

@ ?<@<A B -AA =

B<A -

32. Which is the simplest file structure? 2a4 $e/uential 2.4 +ndexed 2c4 andom 'a( Se,uential 33. Whether Lin'ed List is linear or &on3linear data structure? According to Access strategies .inked list is a linear one. According to Storage .inked .ist is a !on7linear one. 3*. !raw a .inary Dree for the expression : 6 9 " 3 2, 8 !4 9 2> G A4 7 8

3-. <or the following ,E"EL code% draw the "inary tree? A< S*:D2!*M$2C. A- !A 2. A@ /#$S*M!A 2 4#C G'<A(. A@ .AS*M!A 2 4#C G'<A(. A- H2A$MO/MS*:DH. A@ /#$S*MS2 4#C GG. A@ S2CO!DMS2 4#C GG. A< S*:D2!*M$2C

A!A 2

AH2A$MO/MS*:DH

A@
/#$S*M!A 2

A@
.AS*M!A 2 /#$S*MS2

A@
S2CO!DMS2

A@

<A

C Aptitude

C Aptitude
N!te / All the programs are tested under *urbo CKC99 compilers. #t is assumed that, 4rograms run under DOS environment, *he underlying machine is an 3D? system, 4rogram is compiled using *urbo CKC99 compiler. *he program output may depend on the information based on this assumptions 'for e3ample sizeof'int( >> - may be assumed(. 4redict the output or error's( for the following5 1. void main24 H int const 9 pI-J printf2KLdK%8829p44J M Ans)er/ Compiler error5 Cannot modify a constant value. 01p2anati!n5 p is a pointer to a Nconstant integerN. %ut we tried to change the value of the Nconstant integerN. 2. main24 H char sN OIKmanKJ int iJ for2iI@JsN i OJi884 printf2KPnLcLcLcLcK%sN i O%92s8i4%92i8s4%iNsO4J M Ans)er/ mmmm aaaa nnnn 01p2anati!n5 sOiP, 8'i9s(, 8's9i(, iOsP are all different ways of e3pressing the same idea. "enerally array name is the base address for that array. )ere s is the base address. i is the
<<

inde3 numberKdisplacement from the base address. So, indirecting it with 8 is same as sOiP. iOsP may be surprising. %ut in the case of C it is same as sOiP. 3. main24 H float me I 1.1J dou.le you I 1.1J if2meIIyou4 printf2K+ love QK4J else printf2K+ hate QK4J M Ans)er/ # hate : 01p2anati!n5 /or floating point numbers (float, double, long double) the values cannot be predicted e3actly. Depending on the number of bytes, the precession with of the value represented varies. /loat takes B bytes and long double takes <A bytes. So float stores A.J with less precision than long double. Rule of Thumb: !ever compare or at7least be cautious when using floating point numbers with relational operators (>> , Q, R, R>, Q>,S> ) . *. main24 H static int var I -J printf2KLd K%var334J if2var4 main24J M Ans)er/ =B@-< 01p2anati!n/ Ehen static storage class is given, it is initialized once. *he change in the value of a static variable is retained even between the function calls. ain is also treated like any other ordinary function, which can be called recursively. -. main24 H int cN OIH2.7%3.*%*%0.5%-MJ int j%9pIc%9/IcJ for2jI@JjR-Jj884 H printf2K Ld K%9c4J 88/J M for2jI@JjR-Jj884H printf2K Ld K%9p4J 88pJ M
<-

M Ans)er/ ------@B?= 01p2anati!n/ #nitially pointer c is assigned to both p and q. #n the first loop, since only q is incremented and not c , the value - will be printed = times. #n second loop p itself is incremented. So the values - @ B ? = will be printed. 0. main24 H extern int iJ iI2@J printf2KLdK%i4J M Ans)er/ Lin'er 1rror 5 :ndefined symbol TMiT 01p2anati!n/ e3tern storage class in the following declaration, extern int i specifies to the compiler that the memory for i is allocated in some other program and that address will be given to the current program at the time of linking. %ut linker finds that no other variable of name i is available in any other program with memory space allocated for it. )ence a linker error has occurred . 5. main24 H int iI31%jI31%'I@%lI2%mJ mIi88((j88(('88SSl88J printf2KLd Ld Ld Ld LdK%i%j%'%l%m4J M Ans)er/ AA<@< 01p2anati!n / .ogical operations always give a result of 1 or 0 . And also the logical A!D 'UU( operator has higher priority over the logical O$ 'VV( operator. So the e3pression 0i!! "" #!! "" $!!% is e3ecuted first. *he result of this e3pression is A '7< UU 7< UU A > A(. !ow the e3pression is A VV - which evaluates to < 'because O$ operator always gives < e3cept for 0A VV A1 combination7 for which it gives A(. So the value of m is <. *he values of other variables are also incremented by <.

<@

7. main24 H char 9pJ printf2KLd Ld K%siCeof29p4%siCeof2p44J M Ans)er/ <01p2anati!n/ *he sizeof'( operator gives the number of bytes taken by its operand. 4 is a character pointer, which needs one byte for storing its value 'a character(. )ence sizeof'8p( gives a value of <. Since it needs two bytes to store the address of the character pointer sizeof'p( gives -. ?. main24 H int iI3J switch2i4 H default:printf2KCeroK4J case 1: printf2KoneK4J .rea'J case 2:printf2KtwoK4J .rea'J case 3: printf2KthreeK4J .rea'J M M Ans)er / three 01p2anati!n / *he default case can be placed anywhere inside the loop. #t is e3ecuted only when all other cases doesnTt match. 1@. main24 H printf2KLxK%31RR*4J M Ans)er/ fffA 01p2anati!n / 7< is internally represented as all <Ts. Ehen left shifted four times the least significant B bits are filled with ATs.*he W3 format specifier specifies that the integer value be printed as a he3adecimal value.

<B

11. main24 H char stringNOIK)ello WorldKJ display2string4J M void display2char 9string4 H printf2KLsK%string4J M Ans)er/ ,ompiler 1rror : *ype mismatch in redeclaration of function display 01p2anati!n / #n third line, when the function &ispl'( is encountered, the compiler doesnTt know anything about the function display. #t assumes the arguments and return types to be integers, 'which is the default type(. Ehen it sees the actual function &ispl'() the arguments and type contradicts with what it has assumed previously. )ence a compile time error occurs. 12. main24 H int cI3 32J printf2KcILdK%c4J M Ans)er/ c>-X 01p2anati!n/ )ere unary minus 'or negation( operator is used twice. Same maths rules applies, ie. minus 8 minus> plus. *ote: )owever you cannot give like 77-. %ecause 77 operator can only be applied to variables as a &e+rement operator 'eg., i77(. - is a constant and not a variable. 13. Tdefine int char main24 H int iI0-J printf2KsiCeof2i4ILdK%siCeof2i44J M Ans)er/ sizeof'i(>< 01p2anati!n/ Since the Ydefine replaces the string int by the macro +h'r

<=

1*. main24 H int iI1@J iIU iV1*J >rintf 2KiILdK%i4J M Ans)er/ i>A 01p2anati!n/ #n the e3pression ,i-1. , !O* 'S( operator has more precedence than 0 Q1 symbol. , is a unary logical operator. Si 'S<A( is A 'not of true is false(. AQ<B is false 'zero(. 1-. TincludeRstdio.hV main24 H char sNOIHWaW%W.W%WcW%WPnW%WcW%WP@WMJ char 9p%9str%9str1J pI(sN3OJ strIpJ str1IsJ printf2KLdK%889p 8 889str13324J M Ans)er/ FF 01p2anati!n/ p is pointing to character TZnT. str< is pointing to character TaT 998p. Np is pointing to TZnT and that is incremented by one.N the ASC## value of TZnT is <A, which is then incremented to <<. *he value of 998p is <<. 998str<, str< is pointing to TaT that is incremented by < and it becomes TbT. ASC## value of TbT is JD. !ow performing '<< 9 JD & @-(, we get FF'N N(X So we get the output FF 55 N N 'Ascii is FF(. 10. TincludeRstdio.hV main24 H int aN2ON2ON2O I H H1@%2%3%*M% H-%0%5%7M MJ int 9p%9/J pI(aN2ON2ON2OJ 9/I999aJ printf2KLd3333LdK%9p%9/4J M Ans)er/ Some"arbage+alue777<A
<?

01p2anati!n/ p>UaO-PO-PO-P you declare only two -D arrays, but you are trying to access the third -D'which you are not declared( it will print garbage values. 8,>888a starting address of a is assigned integer pointer. !ow , is pointing to starting address of a. #f you print 8,, it will print first element of @D array. 15. TincludeRstdio.hV main24 H struct xx H int xI3J char nameNOIKhelloKJ MJ struct xx 9sJ printf2KLdK%s3Vx4J printf2KLsK%s3Vname4J M Ans)er/ Compiler 2rror 01p2anati!n/ Hou should not initialize variables in declaration 17. TincludeRstdio.hV main24 H struct xx H int xJ struct yy H char sJ struct xx 9pJ MJ struct yy 9/J MJ M Ans)er/ Compiler 2rror 01p2anati!n/ *he structure yy is nested within structure 33. )ence, the elements are of yy are to be accessed through the instance of structure 33, which needs an instance of yy to be known. #f the instance is created after defining the structure the compiler will not know about the instance relative to 33. )ence for nested structure yy you have to declare member.
<F

1?. main24 H printf2KPna.K4J printf2KP.siK4J printf2KPrhaK4J M Ans)er/ hai 01p2anati!n/ Zn 7 newline Zb 7 backspace Zr 7 linefeed 2@. main24 H int iI-J printf2KLdLdLdLdLdLdK%i88%i33%88i%33i%i4J M Ans)er/ B==B= 01p2anati!n/ *he arguments in a function call are pushed into the stack from left to right. *he evaluation is by popping out from the stack. and the evaluation is from right to left, hence the result. 21. Tdefine s/uare2x4 x9x main24 H int iJ i I 0*Gs/uare2*4J printf2KLdK%i4J M Ans)er/ ?B 01p2anati!n/ the macro call s,uare'B( will substituted by B8B so the e3pression becomes i > ?BKB8B . Since K and 8 has e,ual priority the e3pression will be evaluated as '?BKB(8B i.e. <?8B > ?B 22. main24 H char 9pIKhai friendsK%9p1J p1IpJ while29pUIWP@W4 889p88J printf2KLs LsK%p%p14J M
<D

Ans)er/ ib;Sgs;foet 01p2anati!n/ 998p99 will be parse in the given order 8p that is value at the location currently pointed by p will be taken 998p the retrieved value will be incremented when X is encountered the location will be incremented that is p99 will be e3ecuted )ence, in the while loop initial value pointed by p is 0h1, which is changed to 0i1 by e3ecuting 998p and pointer moves to point, 0a1 which is similarly changed to 0b1 and so on. Similarly blank space is converted to 0S1. *hus, we obtain value in p becomes [ib;S gs;foet\ and since p reaches 0ZA1 and p< points to p thus p<doesnot print anything. 23. Tinclude Rstdio.hV Tdefine a 1@ main24 H Tdefine a -@ printf2KLdK%a4J M Ans)er/ =A 01p2anati!n/ *he preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken. 2*. Tdefine clrscr24 1@@ main24 H clrscr24J printf2KLdPnK%clrscr244J M Ans)er/ <AA 01p2anati!n/ 4reprocessor e3ecutes as a seperate pass before the e3ecution of the compiler. So te3tual replacement of clrscr'( to <AA occurs.*he input program to compiler looks like this 5 main'( ] <AAX printf'NWdZnN,<AA(X ^ *ote: <AAX is an e3ecutable statement but with no action. So it doesnTt give any problem
<J

2-. main24 H printf2KLpK%main4J M Ans)er/ Some address will be printed. 01p2anati!n/ /unction names are ;ust addresses ';ust like array names are addresses(. main'( is also a function. So the address of function main will be printed. Wp in printf specifies that the argument is an address. *hey are printed as he3adecimal numbers. -F( main'( ] clrscr'(X ^ clrscr'(X Ans)er/ !o outputKerror 01p2anati!n/ *he first clrscr'( occurs inside a function. So it becomes a function call. #n the second clrscr'(X is a function declaration 'because it is not inside any function(. -D( enum colors ]%.AC_,%.:2,"$22!^ main'( ] printf'NWd..Wd..WdN,%.AC_,%.:2,"$22!(X return'<(X ^ Ans)er/ A..<..01p2anati!n/ enum assigns numbers starting from A, if not e3plicitly defined. -J( void main'( ] char far 8farther,8farthestX printf'NWd..WdN,sizeof'farther(,sizeof'farthest((X ^ Ans)er/ B..-A

01p2anati!n/ the second pointer is of char type and not a far pointer @A( main'( ] int i>BAA,;>@AAX printf'NWd..WdN(X ^ Ans)er/ BAA..@AA 01p2anati!n/ printf takes the values of the first two assignments of the program. Any number of printfTs may be given. All of them take only the first two values. #f more number of assignments given in the program,then printf will take garbage values. main'( ] char 8pX p>N)elloNX printf'NWcZnN,8U8p(X ^ Ans)er/ ) 01p2anati!n/ 8 is a dereference operator U is a reference operator. *hey can be applied any number of times provided it is meaningful. )ere p points to the first character in the string N)elloN. 8p dereferences it and so its value is ). Again U references it to an address and 8 dereferences it to the value ). main'( ] int i><X while 'iR>=( ] printf'NWdN,i(X if 'iQ-( goto hereX i99X ^ ^ fun'( ] here5 printf'N44N(X^

@<(

@-(

-<

Ans)er/ Compiler error5 :ndefined label ThereT in function main 01p2anati!n/ .abels have functions scope, in other words *he scope of the labels is limited to functions . *he label ThereT is available in function fun'( )ence it is not visible in function main. @@( main'( ] static char namesO=PO-AP>]NpascalN,NadaN,NcobolN,NfortranN,NperlN^X int iX char 8tX t>namesO@PX namesO@P>namesOBPX namesOBP>tX for 'i>AXiR>BXi99( printf'NWsN,namesOiP(X ^ Ans)er/ Compiler error5 .value re,uired in function main 01p2anati!n/ Array names are pointer constants. So it cannot be modified. void main'( ] int i>=X printf'NWdN,i99 9 99i(X ^ Ans)er/ Output Cannot be predicted e3actly. 01p2anati!n/ Side effects are involved in the evaluation of i void main'( ] int i>=X printf'NWdN,i99999i(X ^ Ans)er/ Compiler 2rror 01p2anati!n/ *he e3pression i99999i is parsed as i 99 99 9 i which is an illegal combination of operators. YincludeRstdio.hQ

@B(

@=(

@?(
--

main'( ] int i><,;>-X switch'i( ] case <5 printf'N"OODN(X breakX case ;5 printf'N%ADN(X breakX ^ ^ Ans)er/ Compiler 2rror5 Constant e3pression re,uired in function main. 01p2anati!n/ *he case statement can have only constant e3pressions 'this implies that we cannot use variable names directly so an error(. *ote: 2numerated types can be used in case statements. @F( main'( ] int iX printf'NWdN,scanf'NWdN,Ui((X KK value <A is given as input here ^ Ans)er/ < 01p2anati!n/ Scanf returns number of items successfully read and not <KA. )ere <A is given as input which should have been scanned successfully. So number of items read is <. Ydefine f'g,g-( gYYgmain'( ] int var<-><AAX printf'NWdN,f'var,<-((X ^ Ans)er/ <AA main'( ] int i>AX for'Xi99Xprintf'NWdN,i(( X
-@

@D(

@J(

printf'NWdN,i(X ^ Ans)er/ < 01p2anati!n/ %efore entering into the for loop the checking condition is NevaluatedN. )ere it evaluates to A 'false( and comes out of the loop, and i is incremented 'note the semicolon after the for loop(. BA( YincludeRstdio.hQ main'( ] char sOP>]TaT,TbT,TcT,TZnT,TcT,TZAT^X char 8p,8str,8str<X p>UsO@PX str>pX str<>sX printf'NWdN,998p 9 998str<7@-(X ^ Ans)er/ 01p2anati!n/ p is pointing to character TZnT.str< is pointing to character TaT 998p meAnswer5Np is pointing to TZnT and that is incremented by one.N the ASC## value of TZnT is <A. then it is incremented to <<. the value of 998p is <<. 9 98str< meAnswer5Nstr< is pointing to TaT that is incremented by < and it becomes TbT. ASC## value of TbT is JD. both << and JD is added and result is subtracted from @-. i.e. '<<9JD7@-(>FF'N N(X B<( YincludeRstdio.hQ main'( ] struct 33 ] int 3>@X char nameOP>NhelloNX ^X struct 33 8s>malloc'sizeof'struct 33((X printf'NWdN,s7Q3(X printf'NWsN,s7Qname(X ^ Ans)er/ Compiler 2rror 01p2anati!n/

-B

#nitialization should not be done for structure members inside the structure declaration B-( YincludeRstdio.hQ main'( ] struct 33 ] int 3X struct yy ] char sX struct 33 8pX ^X struct yy 8,X ^X ^ Ans)er/ Compiler 2rror 01p2anati!n/ in the end of nested structure yy a member have to be declared. main'( ] e3tern int iX i>-AX printf'NWdN,sizeof'i((X ^ Ans)er/ .inker error5 undefined symbol TMiT. 01p2anati!n/ e3tern declaration specifies that the variable i is defined somewhere else. *he compiler passes the e3ternal variable to be resolved by the linker. So compiler doesnTt find an error. During linking the linker searches for the definition of i. Since it is not found the linker flags an error. main'( ] printf'NWdN, out(X ^ int out><AAX Ans)er/ Compiler error5 undefined symbol out in function main. 01p2anati!n/

B@(

BB(

-=

*he rule is that a variable is available for use from the point of declaration. 2ven though a is a global variable, it is not available for main. )ence an error. B=( main'( ] e3tern outX printf'NWdN, out(X ^ int out><AAX Ans)er/ <AA 01p2anati!n/ *his is the correct way of writing the previous program. main'( ] show'(X ^ void show'( ] printf'N#Tm the greatestN(X ^ Ans)er/ Compier error5 *ype mismatch in redeclaration of show. 01p2anati!n/ Ehen the compiler sees the function show it doesnTt know anything about it. So the default return type 'ie, int( is assumed. %ut when compiler sees the actual definition of show mismatch occurs since it is declared as void. )ence the error. *he solutions are as follows5 <. declare void show'( in main'( . -. define show'( before main'(. @. declare e3tern void show'( before the use of show'(. main' ( ] int aO-PO@PO-P > ]]]-,B^,]F,D^,]@,B^^,]]-,-^,]-,@^,]@,B^^^X printf'[Wu Wu Wu Wd Zn\,a,8a,88a,888a(X printf'[Wu Wu Wu Wd Zn\,a9<,8a9<,88a9<,888a9<(X ^ Ans)er/ <AA, <AA, <AA, <<B, <AB, <A-, @ 01p2anati!n/ *he given array is a @7D one. #t can also be viewed as a <7D array.

B?(

BF(

-?

- B F D @ B - @ @ B <AA <A- <AB <A? <AD <<A <<- <<B <<? <<D <-A <-thus, for the first printf statement a, 8a, 88a give address of first element . since the indirection 888a gives the value. )ence, the first line of the output. for the second printf a9< increases in the third dimension thus points to value at <<B, 8a9< increments in second dimension thus points to <AB, 88a 9< increments the first dimension thus points to <A- and 888a9< first gets the value at first location and then increments it by <. )ence, the output. BD( main' ( ] int aO P > ]<A,-A,@A,BA,=A^,;,8pX for';>AX ;R=X ;99( ] printf'[Wd\ ,8a(X a99X ^ p > aX for';>AX ;R=X ;99( ] printf'[Wd \ ,8p(X p99X ^ ^ Ans)er/ Compiler error5 lvalue re,uired. 01p2anati!n/ 2rror is in line with statement a99. *he operand must be an lvalue and may be of any of scalar type for the any operator, array name only when subscripted is an lvalue. Simply array name is a non7modifiable lvalue. BJ( main' ( ] static int aO P > ]A,<,-,@,B^X int 8pO P > ]a,a9<,a9-,a9@,a9B^X int 88ptr > pX ptr99X printf'[Zn Wd Wd Wd\, ptr7p, 8ptr7a, 88ptr(X 8ptr99X printf'[Zn Wd Wd Wd\, ptr7p, 8ptr7a, 88ptr(X 899ptrX

-F

printf'[Zn Wd Wd Wd\, ptr7p, 8ptr7a, 88ptr(X 998ptrX printf'[Zn Wd Wd Wd\, ptr7p, 8ptr7a, 88ptr(X ^ Ans)er/ 111 222 333 3** 01p2anati!n/ .et us consider the array and the two pointers with some address ' A < @ B <AA <A<AB <A? <AD p <AA <A<AB <A? <AD <AAA <AA- <AAB <AA? <AAD ptr <AAA -AAA After e3ecution of the instruction ptr99 value in ptr becomes <AA-, if scaling factor for integer is - bytes. !ow ptr & p is value in ptr & starting location of array p, '<AA- & <AAA( K 'scaling factor( > <, 8ptr & a > value at address pointed by ptr & starting value of array a, <AA- has a value <A- so the value is '<A- & <AA(K'scaling factor( > <, 88ptr is the value stored in the location pointed by the pointer of ptr > value pointed by value pointed by <AA- > value pointed by <A- > <. )ence the output of the firs printf is <, <, <. After e3ecution of 8ptr99 increments value of the value in ptr by scaling factor, so it becomes<AAB. )ence, the outputs for the second printf are ptr & p > -, 8ptr & a > -, 88ptr > -. After e3ecution of 899ptr increments value of the value in ptr by scaling factor, so it becomes<AAB. )ence, the outputs for the third printf are ptr & p > @, 8ptr & a > @, 88ptr > @. After e3ecution of 998ptr value in ptr remains the same, the value pointed by the value is incremented by the scaling factor. So the value in array p at location <AA? changes from <A? <A <AD,. )ence, the outputs for the fourth printf are ptr & p > <AA? & <AAA > @, 8ptr & a > <AD & <AA > B, 88ptr > B. =A( main' ( ] char 8,X int ;X for ';>AX ;R@X ;99( scanf'[Ws\ ,',9;((X for ';>AX ;R@X ;99( printf'[Wc\ ,8',9;((X for ';>AX ;R@X ;99( printf'[Ws\ ,',9;((X

-D

^ 01p2anati!n/ )ere we have only one pointer to type char and since we take input in the same pointer thus we keep writing over in the same location, each time shifting the pointer value by <. Suppose the inputs are O:S2, *$AC_ and +#$*:A.. *hen for the first input suppose the pointer starts at location <AA then the input one is stored as O : S 2 ZA Ehen the second input is given the pointer is incremented as ; value becomes <, so the input is filled in memory starting from <A<. * $ A C _ ZA *he third input starts filling from the location <A* + # $ * : A . ZA *his is the final value stored . *he first printf prints the values at the position ,, ,9< and ,9- > * + *he second printf prints three strings starting from locations ,, ,9<, ,9i.e *+#$*:A., *+#$*:A. and +#$*:A.. =<( main' ( ] void 8vpX char ch > 0g1, 8cp > [goofy\X int ; > -AX vp > UchX printf'[Wc\, 8'char 8(vp(X vp > U;X printf'[Wd\,8'int 8(vp(X vp > cpX printf'[Ws\,'char 8(vp 9 @(X ^ Ans)er/ g-Afy 01p2anati!n/ Since a void pointer is used it can be type casted to any other type pointer. vp > Uch stores address of char ch and the ne3t statement prints the value stored in vp after type casting it to the proper data type pointer. the output is 0g1. Similarly the output from second printf is 0-A1. *he third printf statement type casts it to print the string from the B th value hence the output is 0fy1. main ' ( ] static char 8sO P > ][black\, [white\, [yellow\, [violet\^X char 88ptrO P > ]s9@, s9-, s9<, s^, 888pX p > ptrX 8899pX

=-(

-J

printf'[Ws\,877899p 9 @(X ^ Ans)er/ ck 01p2anati!n/ #n this problem we have an array of char pointers pointing to start of B strings. *hen we have ptr which is a pointer to a pointer of type char and a variable p which is a pointer to a pointer to a pointer of type char. p hold the initial value of ptr, i.e. p > s9@. *he ne3t statement increment value in p by < , thus now value of p > s9-. #n the printf statement the e3pression is evaluated 899p causes gets value s9< then the pre decrement is e3ecuted and we get s9< & < > s . the indirection operator now gets the value from the array of s and adds @ to the starting address. *he string is printed starting from this position. *hus, the output is 0ck1. =@( main'( ] int i, nX char 83 > [girl\X n > strlen'3(X 83 > 3OnPX for'i>AX iRnX 99i( ] printf'[WsZn\,3(X 399X ^ ^ Ans)er/ 'blank space( irl rl l 01p2anati!n/ )ere a string 'a pointer to char( is initialized with a value [girl\. *he strlen function returns the length of the string, thus n has a value B. *he ne3t statement assigns value at the nth location '0ZA1( to the first location. !ow the string becomes [ZAirl\ . !ow the printf statement prints the string after each iteration it increments it starting position. .oop starts from A to B. *he first time 3OAP > 0ZA1 hence it prints nothing and pointer value is incremented. *he second time it prints from 3O<P i.e [irl\ and the third time it prints [rl\ and the last time it prints [l\ and the loop terminates. int i,;X for'i>AXiR><AXi99( ] ;9>=X

=B(

@A

assert'iR=(X ^ Ans)er/ $untime error5 Abnormal program termination. assert failed 'iR=(, Rfile nameQ,Rline numberQ 01p2anati!n/ asserts are used during debugging to make sure that certain conditions are satisfied. #f assertion fails, the program will terminate reporting the same. After debugging use, Yundef !D2%:" and this will disable all the assertions from the source code. Assertion is a good debugging tool to make use of. ==( main'( ] int i>7<X 9iX printf'Ni > Wd, 9i > Wd ZnN,i,9i(X ^ Ans)er/ i > 7<, 9i > 7< 01p2anati!n/ :nary 9 is the only dummy operator in C. Ehere7ever it comes you can ;ust ignore it ;ust because it has no effect in the e3pressions 'hence the name dummy operator(. Ehat are the files which are automatically opened when a C file is e3ecuted` Ans)er/ stdin, stdout, stderr 'standard input,standard output,standard error(.

=?(

=F( what will be the position of the file marker` a5 fseek'ptr,A,S22_MS2*(X b5 fseek'ptr,A,S22_MC:$(X Ans)er / a5 *he S22_MS2* sets the file position marker to the starting of the file. b5 *he S22_MC:$ sets the file position marker to the current position of the file. =D( main'( ] char nameO<AP,sO<-PX scanf'N ZNWO6ZNPZNN,s(X ^ )ow scanf will e3ecute` Ans)er/

@<

/irst it checks for the leading white space and discards it. *hen it matches with a ,uotation mark and then it reads all characters up to another ,uotation mark. =J( Ehat is the problem with the following code segment` while ''fgets'receiving array,=A,fileMptr(( S> 2O/( X Ans)er 3 01p2anati!n/ fgets returns a pointer. So the correct end of file check is checking for S> !:... main'( ] main'(X ^ Ans)er/ $untime error 5 Stack overflow. 01p2anati!n/ main function calls itself again and again. 2ach time the function is called its return address is stored in the call stack. Since there is no condition to terminate the function call, the call stack overflows at runtime. So it terminates the program and results in an error. main'( ] char 8cptr,cX void 8vptr,vX c><AX v>AX cptr>UcX vptr>UvX printf'NWcWvN,c,v(X ^ Ans)er/ Compiler error 'at line number B(5 size of v is :nknown. 01p2anati!n/ Hou can create a variable of type void 8 but not of type void, since void is an empty type. #n the second line you are creating variable vptr of type void 8 and v of type void hence an error. main'( ] char 8str<>NabcdNX char str-OP>NabcdNX printf'NWd Wd WdN,sizeof'str<(,sizeof'str-(,sizeof'NabcdN((X ^ Ans)er/ -==

?A(

?<(

?-(

@-

01p2anati!n/ #n first sizeof, str< is a character pointer so it gives you the size of the pointer variable. #n second sizeof the name str- indicates the name of the array whose size is = 'including the TZAT termination character(. *he third sizeof is similar to the second one. ?@( main'( ] char notX not>S-X printf'NWdN,not(X ^ Ans)er/ A 01p2anati!n/ S is a logical operator. #n C the value A is considered to be the boolean value /A.S2, and any non7zero value is considered to be the boolean value *$:2. )ere - is a non7zero value so *$:2. S*$:2 is /A.S2 'A( so it prints A. Ydefine /A.S2 7< Ydefine *$:2 < Ydefine !:.. A main'( ] if'!:..( puts'N!:..N(X else if'/A.S2( puts'N*$:2N(X else puts'N/A.S2N(X ^ Ans)er/ *$:2 01p2anati!n5 *he input program to the compiler after processing by the preprocessor is, main'(] if'A( puts'N!:..N(X else if'7<( puts'N*$:2N(X else puts'N/A.S2N(X ^ 4reprocessor doesnTt replace the values given inside the double ,uotes. *he check by if condition is boolean value false so it goes to else. #n second if 7< is boolean value true hence N*$:2N is printed.

?B(

@@

?=(

main'( ] int k><X printf'NWd>>< is NNWsN,k,k>><`N*$:2N5N/A.S2N(X ^ Ans)er/ <>>< is *$:2 01p2anati!n/ Ehen two strings are placed together 'or separated by white7space( they are concatenated 'this is called as NstringizationN operation(. So the string is as if it is given as NWd>>< is WsN. *he conditional operator' `5 ( evaluates to N*$:2N. main'( ] int yX scanf'NWdN,Uy(X KK input given is -AAA if' 'yWB>>A UU yW<AA S> A( VV yW<AA >> A ( printf'NWd is a leap yearN(X else printf'NWd is not a leap yearN(X ^ Ans)er/ -AAA is a leap year 01p2anati!n/ An ordinary program to check if leap year or not. Ydefine ma3 = Ydefine int arr<Oma3P main'( ] typedef char arr-Oma3PX arr< list>]A,<,-,@,B^X arr- name>NnameNX printf'NWd WsN,listOAP,name(X ^ Ans)er/ Compiler error 'in the line arr< list > ]A,<,-,@,B^( 01p2anati!n/ arr- is declared of type array of size = of characters. So it can be used to declare the variable name of the type arr-. %ut it is not the case of arr<. )ence an error. Rule of Thumb: Ydefines are used for te3tual replacement whereas typedefs are used for declaring new types.

??(

?F(

@B

?D(

int i><AX main'( ] e3tern int iX ] int i>-AX ] const volatile unsigned i>@AX printf'NWdN,i(X ^ printf'NWdN,i(X ^ printf'NWdN,i(X ^ Ans)er/ @A,-A,<A 01p2anati!n/ T]T introduces new block and thus new scope. #n the innermost block i is declared as, const volatile unsigned which is a valid declaration. i is assumed of type int. So printf prints @A. #n the ne3t block, i has value -A and so printf prints -A. #n the outermost block, i is declared as e3tern, so no storage space is allocated for it. After compilation is over the linker resolves it to global variable i 'since it is the only variable visible there(. So it prints iTs value as <A. main'( ] int 8;X ] int i><AX ;>UiX ^ printf'NWdN,8;(X ^ Ans)er/ <A 01p2anati!n5 *he variable i is a block level variable and the visibility is inside that block only. %ut the lifetime of i is lifetime of the function so it lives upto the e3it of main function. Since i is still allocated space, 8; prints the value stored in i since ; points i. main'( ]

?J(

FA(
@=

int i>7<X 7iX printf'Ni > Wd, 7i > Wd ZnN,i,7i(X ^ Ans)er/ i > 7<, 7i > < 01p2anati!n/ 7i is e3ecuted and this e3ecution doesnTt affect the value of i. #n printf first you ;ust print the value of i. After that the value of the e3pression 7i > 7'7<( is printed. F<( YincludeRstdio.hQ main'( ] const int i>BX float ;X ; > 99iX printf'NWd WfN, i,99;(X ^ Ans)er5 Compiler error 01p2anati!n5 i is a constant. you cannot change the value of constant YincludeRstdio.hQ main'( ] int aO-PO-PO-P > ] ]<A,-,@,B^, ]=,?,F,D^ ^X int 8p,8,X p>UaO-PO-PO-PX 8,>888aX printf'NWd..WdN,8p,8,(X ^ Ans)er/ garbagevalue..< 01p2anati!n/ p>UaO-PO-PO-P you declare only two -D arrays. but you are trying to access the third -D'which you are not declared( it will print garbage values. 8,>888a starting address of a is assigned integer pointer. now , is pointing to starting address of a.if you print 8, meAnswer5it will print first element of @D array. YincludeRstdio.hQ main'( ] register i>=X

F-(

F@(

@?

char ;OP> NhelloNX printf'NWs WdN,;,i(X ^ Ans)er/ hello = 01p2anati!n5 if you declare i as register compiler will treat it as ordinary integer and it will take integer value. i value may be stored either in register or in memory. FB( main'( ] int i>=,;>?,zX printf'NWdN,i999;(X ^ Ans)er/ << 01p2anati!n/ the e3pression i999; is treated as 'i99 9 ;( struct aaa] struct aaa 8prevX int iX struct aaa 8ne3tX ^X main'( ] struct aaa abc,def,ghi,;klX int 3><AAX abc.i>AXabc.prev>U;klX abc.ne3t>UdefX def.i><Xdef.prev>UabcXdef.ne3t>UghiX ghi.i>-Xghi.prev>UdefX ghi.ne3t>U;klX ;kl.i>@X;kl.prev>UghiX;kl.ne3t>UabcX 3>abc.ne3t7Qne3t7Qprev7Qne3t7QiX printf'NWdN,3(X ^ Ans)er/ 01p2anati!n/ above all statements form a double circular linked listX abc.ne3t7Qne3t7Qprev7Qne3t7Qi this one points to NghiN node the value of at particular node is -. struct point

F?(

FF(
@F

] int 3X int yX ^X struct point origin,8ppX main'( ] pp>UoriginX printf'Norigin is'WdWd(ZnN,'8pp(.3,'8pp(.y(X printf'Norigin is 'WdWd(ZnN,pp7Q3,pp7Qy(X ^ Ans)er/ origin is'A,A( origin is'A,A( 01p2anati!n5 pp is a pointer to structure. we can access the elements of the structure either with arrow mark or with indirection operator. *ote: Since structure point is globally declared 3 U y are initialized as zeroes FD( main'( ] int i>MlMabc'<A(X printf'NWdZnN,77i(X ^ int MlMabc'int i( ] return'i99(X ^ Ans)er/ J 01p2anati!n/ return'i99( it will first return i and then increments. i.e. <A will be returned. main'( ] char 8pX int 8,X long 8rX p>,>r>AX p99X ,99X r99X printf'NWp...Wp...WpN,p,,,r(X

FJ(

@D

^ Ans)er/ AAA<...AAA-...AAAB 01p2anati!n/ 99 operator when applied to pointers increments address according to their corresponding data7types. DA( main'( ] char c>T T,3,convert'z(X getc'c(X if''cQ>TaT( UU 'cR>TzT(( 3>convert'c(X printf'NWcN,3(X ^ convert'z( ] return z7@-X ^ Ans)er/ Compiler error 01p2anati!n/ declaration of convert and format of getc'( are wrong. main'int argc, char 88argv( ] printf'Nenter the characterN(X getchar'(X sum'argvO<P,argvO-P(X ^ sum'num<,num-( int num<,num-X ] return num<9num-X ^ Ans)er/ Compiler error. 01p2anati!n/ argvO<P U argvO-P are strings. *hey are passed to the function sum without converting it to integer values. Y include Rstdio.hQ int oneMdOP>]<,-,@^X main'( ] int 8ptrX

D<(

D-(

@J

ptr>oneMdX ptr9>@X printf'NWdN,8ptr(X ^ Ans)er5 garbage value 01p2anati!n/ ptr pointer is pointing to out of the array range of oneMd. D@( Y includeRstdio.hQ aaa'( ] printf'NhiN(X ^ bbb'(] printf'NhelloN(X ^ ccc'(] printf'NbyeN(X ^ main'( ] int '8ptrO@P('(X ptrOAP>aaaX ptrO<P>bbbX ptrO-P>cccX ptrO-P'(X ^ Ans)er5 bye 01p2anati!n/ ptr is array of pointers to functions of return type int.ptrOAP is assigned to address of the function aaa. Similarly ptrO<P and ptrO-P for bbb and ccc respectively. ptrO-P'( is in effect of writing ccc'(, since ptrO-P points to ccc. YincludeRstdio.hQ main'( ] /#.2 8ptrX char iX ptr>fopen'Nzzz.cN,NrN(X while''i>fgetch'ptr((S>2O/( printf'NWcN,i(X ^ Ans)er/ contents of zzz.c followed by an infinite loop 01p2anati!n/

D=(

BA

*he condition is checked against 2O/, it should be checked against !:... D?( main'( ] int i >AX;>AX if'i UU ;99( printf'NWd..WdN,i99,;(X printf'NWd..Wd,i,;(X ^ Ans)er/ A..A 01p2anati!n/ *he value of i is A. Since this information is enough to determine the truth value of the boolean e3pression. So the statement following the if statement is not e3ecuted. *he values of i and ; remain unchanged and get printed. main'( ] int iX i > abc'(X printf'NWdN,i(X ^ abc'( ] MAG > <AAAX ^ Ans)er/ <AAA 01p2anati!n/ !ormally the return value from the function is through the information from the accumulator. )ere MA) is the pseudo global variable denoting the accumulator. )ence, the value of the accumulator is set <AAA so the function returns value <AAA. int iX main'(] int tX for ' t>BXscanf'NWdN,Ui(7tXprintf'NWdZnN,i(( printf'NWd77N,t77(X ^ KK #f the inputs are A,<,-,@ find the oKp Ans)er/ B77A @77<

DF(

DD(

B<

-7701p2anati!n/ .et us assume some 3> scanf'NWdN,Ui(7t the values during e3ecution will be, t i 3 B A 7B @ < 7A DJ( main'(] int a> AXint b > -AXchar 3 ><Xchar y ><AX if'a,b,3,y( printf'NhelloN(X ^ Ans)er/ hello 01p2anati!n/ *he comma operator has associativity from left to right. Only the rightmost value is returned and the other values are evaluated and ignored. *hus the value of last variable y is returned to check in if. Since it is a non zero value if becomes true so, NhelloN will be printed. main'(] unsigned int iX for'i><XiQ7-Xi77( printf'Nc aptitudeN(X ^ 01p2anati!n/ i is an unsigned integer. #t is compared with a signed value. Since the both types doesnTt match, signed is promoted to unsigned value. *he unsigned e,uivalent of 7- is a huge value so condition becomes false and control comes out of the loop. #n the following pgm add a stmt in the function fun such that the address of TaT gets stored in T;T. main'(] int 8 ;X void fun'int 88(X fun'U;(X ^ void fun'int 88k( ] int a >AX K8 add a stmt here8K ^ Ans)er/ 8k > Ua

JA(

J<(

B-

01p2anati!n/ *he argument of the function is a pointer to a pointer. J-( Ehat are the following notations of defining functions known as` i. int abc'int a,float b( ] K8 some code 8K ^ ii. int abc'a,b( int aX float bX ] K8 some code8K ^ Ans)er/ i. A!S# C notation ii. _ernighan U $itche notation main'( ] char 8pX p>NWdZnNX p99X p99X printf'p7-,@AA(X ^ Ans)er/ @AA 01p2anati!n/ *he pointer points to W since it is incremented twice and again decremented by -, it points to TWdZnT and @AA is printed. main'(] char aO<AAPX aOAP>TaTXaO<PP>TbTXaO-P>TcTXaOBP>TdTX abc'a(X ^ abc'char aOP(] a99X printf'NWcN,8a(X a99X printf'NWcN,8a(X ^ 01p2anati!n/ *he base address is modified only in function and as a result a points to TbT then after incrementing to TcT so bc will be printed.

J@(

JB(

B@

J=(

func'a,b( int a,bX ] return' a> 'a>>b( (X ^ main'( ] int process'(,func'(X printf'N*he value of process is Wd SZn N,process'func,@,?((X ^ process'pf,val<,val-( int '8pf( '(X int val<,val-X ] return''8pf( 'val<,val-((X ^ Ans)er/ *he value if process is A S 01p2anati!n/ *he function TprocessT has @ parameters 7 <, a pointer to another function and @, integers. Ehen this function is invoked from main, the following substitutions for formal parameters take place5 func for pf, @ for val< and ? for val-. *his function returns the result of the operation performed by the function TfuncT. *he function func has two integer parameters. *he formal parameters are substituted as @ for a and ? for b. since @ is not e,ual to ?, a>>b returns A. therefore the function returns A which in turn is returned by the function TprocessT. void main'( ] static int i>=X if'77i(] main'(X printf'NWd N,i(X ^ ^ Ans)er/ AAAA 01p2anati!n/ *he variable N#N is declared as static, hence memory for # will be allocated for only once, as it encounters the statement. *he function main'( will be called recursively unless # becomes e,ual to A, and since main'( is recursively called, so the value of static # ie., A will be printed every time the control is returned. void main'( ]

J?(

JF(
BB

int k>ret'sizeof'float((X printf'NZn here value is WdN,99k(X ^ int ret'int ret( ] ret 9> -.=X return'ret(X ^ Ans)er/ )ere value is F 01p2anati!n/ *he int ret'int ret(, ie., the function name and the argument name can be the same. /irstly, the function ret'( is called in which the sizeof'float( ie., B is passed, after the first e3pression the value in ret will be ?, as ret is integer hence the value stored in ret will have implicit type conversion from float to int. *he ret is returned in main'( it is printed after and preincrement. JD( void main'( ] char aOP>N<-@B=ZANX int i>strlen'a(X printf'Nhere in @ WdZnN,99i(X ^ Ans)er/ here in @ ? 01p2anati!n/ *he char array TaT will hold the initialized string, whose length will be counted from A till the null character. )ence the T#T will hold the value e,ual to =, after the pre7increment in the printf statement, the ? will be printed. void main'( ] unsigned giveit>7<X int gotitX printf'NWu N,99giveit(X printf'NWu ZnN,gotit>77giveit(X ^ Ans)er/ A ?==@= 01p2anati!n/ void main'( ] int iX char aOP>NZANX

JJ(

<AA(

B=

if'printf'NWsZnN,a(( printf'NOk here ZnN(X else printf'N/orget itZnN(X ^ Ans)er/ Ok here 01p2anati!n/ 4rintf will return how many characters does it print. )ence printing a null character returns < which makes the if statement true, thus NOk hereN is printed. <A<( void main'( ] void 8vX int integer>-X int 8i>UintegerX v>iX printf'NWdN,'int8(8v(X ^ Ans)er/ Compiler 2rror. Ee cannot apply indirection on type void8. 01p2anati!n/ +oid pointer is a generic pointer type. !o pointer arithmetic can be done on it. +oid pointers are normally used for, <. 4assing generic pointers to functions and returning such pointers. -. As a intermediate pointer type. @. :sed when the e3act pointer type will be known at a later point of time. void main'( ] int i>i99,;>;99,k>k99X printf'[WdWdWd\,i,;,k(X ^ Ans)er/ "arbage values. 01p2anati!n/ 6n identifier is availa.le to use in program code from the point of its declaration. So e3pressions such as i > i99 are valid statements. *he i, ; and k are automatic variables and so they contain some garbage value. =ar.age in is gar.age out 2=+=E4. void main'(

<A-(

<A@(
B?

] static int i>i99, ;>;99, k>k99X printf'[i > Wd ; > Wd k > Wd\, i, ;, k(X ^ Ans)er/ i><;><k>< 01p2anati!n/ Since static variables are initialized to zero by default. <AB( void main'( ] while'<(] if'printf'NWdN,printf'NWdN((( breakX else continueX ^ ^ Ans)er/ "arbage values 01p2anati!n/ *he inner printf e3ecutes first to print some garbage value. *he printf returns no of characters printed and this value also cannot be predicted. Still the outer printf prints something and so returns a non7zero value. So it encounters the break statement and comes out of the while statement. main'( ] unsigned int i><AX while'i77Q>A( printf'NWu N,i(X ^ Ans)er/ <A J D F ? = B @ - < A ?==@= ?==@BI.. 01p2anati!n/ Since i is an unsigned integer it can never become negative. So the e3pression i77 Q>A will always be true, leading to an infinite loop. <A=( YincludeRconio.hQ main'( ] int 3,y>-,z,aX if'3>yW-( z>-X a>-X printf'NWd Wd N,z,3(X

<AB(

BF

^ Ans)er/ "arbage7value A 01p2anati!n/ *he value of yW- is A. *his value is assigned to 3. *he condition reduces to if '3( or in other words if'A( and so z goes uninitialized. 45u(6 "u2e/ /heck all control paths to write bug free code. <A?( main'( ] int aO<APX printf'NWdN,8a9<78a9@(X ^ Ans)er/ B 01p2anati!n/ 8a and 78a cancels out. *he result is as simple as < 9 @ > B S <AF( Ydefine prod'a,b( a8b main'( ] int 3>@,y>BX printf'NWdN,prod'39-,y7<((X ^ Ans)er/ <A 01p2anati!n/ *he macro e3pands and evaluates to as5 39-8y7< >Q 39'-8y(7< >Q <A main'( ] unsigned int i>?=AAAX while'i99S>A(X printf'NWdN,i(X ^ Ans)er/ < 01p2anati!n/ !ote the semicolon after the while statement. Ehen the value of i becomes A it comes out of while loop. Due to post7increment on i the value of i while printing is <. <AJ( main'( ] int i>AX
BD

<AD(

while'9'9i77(S>A( i7>i99X printf'NWdN,i(X ^ Ans)er/ 7< 01p2anati!n/ Qnary 8 is the only dummy operator in ,. So it has no effect on the e3pression and now the while loop is, while'i77S>A( which is false and so breaks out of while loop. *he value &< is printed due to the post7 decrement operator. <<@( main'( ] float f>=,g><AX enum]i><A,;>-A,k>=A^X printf'NWdZnN,99k(X printf'NWfZnN,fRR-(X printf'NWlfZnN,fWg(X printf'NWlfZnN,fmod'f,g((X ^ Ans)er/ .ine no =5 2rror5 .value re,uired .ine no ?5 Cannot apply leftshift to float .ine no F5 Cannot apply mod to float 01p2anati!n/ 2numeration constants cannot be modified, so you cannot apply 99. %it7wise operators and W operators cannot be applied on float values. fmod'( is to find the modulus values for floats as W operator is for ints. <<A( main'( ] int i><AX void pascal f'int,int,int(X f'i99,i99,i99(X printf'N WdN,i(X ^ void pascal f'integer 5i,integer5;,integer 5k( ] write'i,;,k(X ^ Ans)er/ Compiler error5 unknown type integer Compiler error5 undeclared function write 01p2anati!n/
BJ

4ascal keyword doesn1t mean that pascal code can be used. #t means that the function follows 4ascal argument passing mechanism in calling the functions. <<<( void pascal f'int i,int ;,int k( ] printf'[Wd Wd Wd\,i, ;, k(X ^ void cdecl f'int i,int ;,int k( ] printf'[Wd Wd Wd\,i, ;, k(X ^ main'( ] int i><AX f'i99,i99,i99(X printf'N WdZnN,i(X i><AX f'i99,i99,i99(X printf'N WdN,i(X ^ Ans)er/ <A << <- <@ <- << <A <@ 01p2anati!n/ 4ascal argument passing mechanism forces the arguments to be called from left to right. cdecl is the normal C argument passing mechanism where the arguments are passed from right to left.

<<-(. Ehat is the output of the program given below main'( ] signed char i>AX for'XiQ>AXi99( X printf'NWdZnN,i(X ^ Ans)er 7<-D 01p2anati!n !otice the semicolon at the end of the for loop. *)e initial value of the i is set to A. *he inner loop e3ecutes to increment the value from A to <-F 'the positive range of char( and then it rotates to the negative value of 7<-D. *he condition in the for loop fails and so comes out of the for loop. #t prints the current value of i that is 7<-D.
=A

<<@( main'( ] unsigned char i>AX for'XiQ>AXi99( X printf'NWdZnN,i(X ^ Ans)er infinite loop 01p2anati!n *he difference between the previous ,uestion and this one is that the char is declared to be unsigned. So the i99 can never yield negative value and iQ>A never becomes false so that it can come out of the for loop. <<B( main'( ] char i>AX for'XiQ>AXi99( X printf'NWdZnN,i(X ^ Ans)er/ %ehavior is implementation dependent. 01p2anati!n/ *he detail if the char is signedKunsigned by default is implementation dependent. #f the implementation treats the char to be signed by default the program will print &<-D and terminate. On the other hand if it considers char to be unsigned by default, it goes to infinite loop. Rule: Hou can write programs that have implementation dependent behavior. %ut dont write programs that depend on such behavior. <<=( #s the following statement a declarationKdefinition. /ind what does it mean` int '83(O<APX Ans)er Definition. 3 is a pointer to array of'size <A( integers. Apply clock7wise rule to find the meaning of this definition. <<?(. Ehat is the output for the program given below typedef enum error*ype]warning, error, e3ception,^errorX main'( ] error g<X
=<

g<><X printf'NWdN,g<(X ^ Ans)er Compiler error5 ultiple declaration for error 01p2anati!n *he name error is used in the two meanings. One means that it is a enumerator constant with value <. *he another use is that it is a type name 'due to typedef( for enum error*ype. "iven a situation the compiler cannot distinguish the meaning of error to know in what sense the error is used5 error g<X g<>errorX KK which error it refers in each case` Ehen the compiler can distinguish between usages then it will not issue error 'in pure technical terms, names can only be overloaded in different namespaces(. N!te5 the e3tra comma in the declaration, enum error*ype]warning, error, e3ception,^ is not an error. An e3tra comma is valid and is provided ;ust for programmer1s convenience. <<F( typedef struct error]int warning, error, e3ceptionX^errorX main'( ] error g<X g<.error ><X printf'NWdN,g<.error(X ^

Ans)er < 01p2anati!n *he three usages of name errors can be distinguishable by the compiler at any instance, so valid 'they are in different namespaces(. *ypedef struct error]int warning, error, e3ceptionX^errorX *his error can be used only by preceding the error by struct kayword as in5 struct error some2rrorX typedef struct error]int warning, error, e3ceptionX^errorX *his can be used only after . 'dot( or 7Q 'arrow( operator preceded by the variable name as in 5 g<.error ><X printf'NWdN,g<.error(X typedef struct error]int warning, error, e3ceptionX^errorX
=-

*his can be used to define variables without using the preceding struct keyword as in5 error g<X Since the compiler can perfectly distinguish between these three usages, it is perfectly legal and valid. *ote *his code is given here to ;ust e3plain the concept behind. #n real programming don1t use such overloading of names. #t reduces the readability of the code. 4ossible doesn1t mean that we should use itS <<D( Yifdef something int some>AX Yendif main'( ] int thing > AX printf'NWd WdZnN, some ,thing(X ^ Ans)er/ Compiler error 5 undefined symbol some 01p2anati!n/ *his is a very simple e3ample for conditional compilation. *he name something is not already known to the compiler making the declaration int some > AX effectively removed from the source code. <<J( Yif something >> A int some>AX Yendif main'( ] int thing > AX printf'NWd WdZnN, some ,thing(X ^ Ans)er AA 01p2anati!n *his code is to show that preprocessor e3pressions are not the same as the ordinary e3pressions. #f a name is not known the preprocessor treats it to be e,ual to zero.
=@

<-A(. Ehat is the output for the following program main'( ] int arr-DO@PO@PX printf'NWdZnN, ''arr-D>>8 arr-D(UU'8 arr-D >> arr-DOAP(( (X ^ Ans)er < 01p2anati!n *his is due to the close relation between the arrays and pointers. ! dimensional arrays are made up of '!7<( dimensional arrays. arr-D is made up of a @ single arrays that contains @ integers each . arr-D arr-DO<P arr-DO-P arr-DO@P

*he name arr-D refers to the beginning of all the @ arrays. 8arr-D refers to the start of the first <D array 'of @ integers( that is the same address as arr-D. So the e3pression 'arr-D >> 8arr-D( is true '<(. Similarly, 8arr-D is nothing but 8'arr-D 9 A(, adding a zero doesn1t change the valueKmeaning. Again arr-DOAP is the another way of telling 8'arr-D 9 A(. So the e3pression '8'arr-D 9 A( >> arr-DOAP( is true '<(. Since both parts of the e3pression evaluates to true the result is true'<( and the same is printed. <-<( void main'( ] if'aA >> 'unsigned int(7<( printf'[Hou can answer this if you know how values are represented in memory\(X ^ Answer Hou can answer this if you know how values are represented in memory 23planation

=B

a 'tilde operator or bit7wise negation operator( operates on A to produce all ones to fill the space for an integer. &< is represented in unsigned value as all <1s and so both are e,ual. <--( int swap'int 8a,int 8b( ] 8a>8a98bX8b>8a78bX8a>8a78bX ^ main'( ] int 3><A,y>-AX swap'U3,Uy(X printf'N3> Wd y > WdZnN,3,y(X ^ Answer 3 > -A y > <A 23planation *his is one way of swapping two values. Simple checking will help understand this. <-@( main'( ] char 8p > [ay,m\X printf'[Wc\,998'p99((X ^ Answer5 b main'( ] int i>=X printf'NWdN,99i99(X ^ Ans)er/ Compiler error5 .value re,uired in function main 01p2anati!n/ 99i yields an rvalue. /or postfi3 99 to operate an lvalue is re,uired. <-=( main'( ] char 8p > [ay,m\X char cX c > 998p99X printf'[Wc\,c(X ^
==

<-B(

Ans)er/ b 01p2anati!n/ *here is no difference between the e3pression 998'p99( and 9 98p99. 4arenthesis ;ust works as a visual clue for the reader to see which e3pression is first evaluated. <-?( int aaa'( ]printf'[)i\(X^ int bbb'(]printf'[hello\(X^ iny ccc'(]printf'[bye\(X^ main'( ] int ' 8 ptrO@P( '(X ptrOAP > aaaX ptrO<P > bbbX ptrO-P >cccX ptrO-P'(X ^ Answer5 b(e 23planation5 int '8 ptrO@P('( says that ptr is an array of pointers to functions that takes no arguments and returns the type int. %y the assignment ptrOAP > aaaX it means that the first function pointer in the array is initialized with the address of the function aaa. Similarly, the other two array elements also get initialized with the addresses of the functions bbb and ccc. Since ptrO-P contains the address of the function ccc, the call to the function ptrO-P'( is same as calling ccc'(. So it results in printing NbyeN. <-F( main'( ] int i>=X printf'[Wd\,i>99i >>?(X ^ Ans)er/ 1 01p2anati!n/ *he e3pression can be treated as i > '99i>>?(, because >> is of higher precedence than > operator. #n the inner e3pression, 99i is e,ual to ? yielding true'<(. )ence the result. <-D(
=?

main'(

] char pO P>NWdZnNX pO<P > TcTX printf'p,?=(X ^ Ans)er/ A 01p2anati!n/ Due to the assignment pO<P > 0c1 the string becomes, [WcZn\. Since this string becomes the format string for printf and ASC## value of ?= is 0A1, the same gets printed. <-J( void ' 8 abc' int, void ' 8def( '( ( ( '(X Answer55 abc is a ptr to a function which takes - parameters .'a(. an integer variable.'b(. a ptrto a funtion which returns void. the return type of the function is void. 01p2anati!n/ Apply the clock7wise rule to find the result. <@A( main'( ] while 'strcmp'[some\,\someZA\(( printf'[Strings are not e,ualZn\(X ^ Ans)er/ !o output 01p2anati!n/ 2nding the string constant with ZA e3plicitly makes no difference. So [some\ and [someZA\ are e,uivalent. So, strcmp returns A 'false( hence breaking out of the while loop. main'( ] char str<OP > ]0s1,1o1,1m1,1e1^X char str-OP > ]0s1,1o1,1m1,1e1,1ZA1^X while 'strcmp'str<,str-(( printf'[Strings are not e,ualZn\(X ^ Ans)er/ [Strings are not e,ual\ [Strings are not e,ual\ I. 01p2anati!n/
=F

<@<(

#f a string constant is initialized e3plicitly with characters, 0ZA1 is not appended automatically to the string. Since str< doesn1t have null termination, it treats whatever the values that are in the following positions as part of the string until it randomly reaches a 0ZA1. So str< and str- are not the same, hence the result. <@-( main'( ] int i > @X for 'Xi99>AX( printf'[Wd\,i(X ^ Ans)er/ Compiler 2rror5 .value re,uired. 01p2anati!n/ As we know that increment operators return rvalues and hence it cannot appear on the left hand side of an assignment operation. <@@( void main'( ] int 8mptr, 8cptrX mptr > 'int8(malloc'sizeof'int((X printf'[Wd\,8mptr(X int 8cptr > 'int8(calloc'sizeof'int(,<(X printf'[Wd\,8cptr(X ^ Ans)er/ garbage7value A 01p2anati!n/ *he memory space allocated by malloc is uninitialized, whereas calloc returns the allocated memory space initialized to zeros. void main'( ] static int iX while'iR><A( 'iQ-(`i995i77X printf'[Wd\, i(X ^ Ans)er/ @-F?F 01p2anati!n/ Since i is static it is initialized to A. #nside the while loop the conditional operator evaluates to false, e3ecuting i77. *his continues till the integer value rotates to positive value '@-F?F(. *he while condition becomes false and hence, comes out of the while loop, printing the i value.

<@B(

=D

<@=(

main'( ] int i><A,;>-AX ; > i, ;`'i,;(`i5;5;X printf'NWd WdN,i,;(X ^

Ans)er/ <A <A 01p2anati!n/ *he *ernary operator ' ` 5 ( is e,uivalent for if7then7else statement. So the ,uestion can be written as5 if'i,;( ] if'i,;( ; > iX else ; > ;X ^ else ; > ;X <@?( <. const char 8aX -. char8 const aX @. char const 8aX 7Differentiate the above declarations. Ans)er/ <. TconstT applies to char 8 rather than TaT ' pointer to a constant char ( 8a>T/T 5 illegal a>N)iN 5 legal -. TconstT applies to TaT rather than to the value of a 'constant pointer to char ( 8a>T/T a>N)iN @. Same as <. <@F( main'( ] int i>=,;><AX i>iU>;UU<AX printf'NWd WdN,i,;(X
=J

5 legal 5 illegal

^ Ans)er/ < <A 01p2anati!n/ *he e3pression can be written as i>'iU>';UU<A((X *he inner e3pression ';UU<A( evaluates to < because ;>><A. i is =. i > =U< is <. )ence the result. <@D( main'( ] int i>B,;>FX ; > ; VV i99 UU printf'NHO: CA!N(X printf'NWd WdN, i, ;(X ^ Ans)er/ B< 01p2anati!n/ Dhe .oolean expression needs to .e evaluated only till the truth value of the expression is not 'nown. ; is not e,ual to zero itself means that the e3pression1s truth value is <. %ecause it is followed by VV and true SS 2anything4 IV true where 2anything4 will not .e evaluated. So the remaining e3pression is not evaluated and so the value of i remains the same. Similarly when UU operator is involved in an e3pression, when any of the operands become false, the whole e3pression1s truth value becomes false and hence the remaining e3pression will not be evaluated. false (( 2anything4 IV false where 2anything4 will not .e evaluated. <@J( main'( ] register int a>-X printf'NAddress of a > WdN,Ua(X printf'N+alue of a > WdN,a(X ^ Ans)er/ Compier 2rror5 TUT on register variable "u2e t! "e(e(6er/ 3 7address !8 9 !perat!r cann!t 6e app2ied !n re+ister varia62es. <BA( main'( ] float i><.=X switch'i( ]
?A

case <5 printf'N<N(X case -5 printf'N-N(X default 5 printf'NAN(X ^ ^ Ans)er/ Compiler 2rror5 switch e3pression not integral 01p2anati!n/ $witch statements can .e applied only to integral types. <B<( main'( ] e3tern iX printf'NWdZnN,i(X ] int i>-AX printf'NWdZnN,i(X ^ ^ Ans)er/ .inker 2rror 5 :nresolved e3ternal symbol i 01p2anati!n/ *he identifier i is available in the inner block and so using e3tern has no use in resolving it. <B-( main'( ] int a>-,8f<,8f-X f<>f->UaX 8f-9>8f-9>a9>-.=X printf'NZnWd Wd WdN,a,8f<,8f-(X ^ Ans)er/ <? <? <? 01p2anati!n/ f< and f- both refer to the same memory location a. So changes through f< and f- ultimately affects only the value of a. <B@( main'( ] char 8p>N"OODNX char aO P>N"OODNX printf'NZn sizeof'p( > Wd, sizeof'8p( > Wd, strlen'p( > WdN, sizeof'p(, sizeof'8p(, strlen'p((X printf'NZn sizeof'a( > Wd, strlen'a( > WdN, sizeof'a(, strlen'a((X ^
?<

Ans)er/ sizeof'p( > -, sizeof'8p( > <, strlen'p( > B sizeof'a( > =, strlen'a( > B 01p2anati!n/ sizeof'p( >Q sizeof'char8( >Q sizeof'8p( >Q sizeof'char( >Q < Similarly, sizeof'a( >Q size of the character array >Q = When siCeof operator is applied to an array it returns the siCeof the array and it is not the same as the sizeof the pointer variable. )ere the sizeof'a( where a is the character array and the size of the array is = because the space necessary for the terminating !:.. character should also be taken into account. <BB( Ydefine D# ' array, type( sizeof'array(Ksizeof'type( main'( ] int arrO<APX printf'[*he dimension of the array is Wd\, D# 'arr, int((X ^ Ans)er/ <A 01p2anati!n/ *he size of integer array of <A elements is <A 8 sizeof'int(. *he macro e3pands to sizeof'arr(Ksizeof'int( >Q <A 8 sizeof'int( K sizeof'int( >Q <A. int D# 'int arrayOP( ] return sizeof'array(Ksizeof'int (X ^ main'( ] int arrO<APX printf'[*he dimension of the array is Wd\, D# 'arr((X ^ Ans)er/ < 01p2anati!n/ 6rrays cannot .e passed to functions as arguments and only the pointers can .e passed. So the argument is e,uivalent to int 8 array 'this is one of the very few places where OP and 8 usage are e,uivalent(. *he return statement becomes, sizeof'int 8(K sizeof'int( that happens to be e,ual in this case. main'(

<B=(

<B?(
?-

] static int aO@PO@P>]<,-,@,B,=,?,F,D,J^X int i,;X static 8pOP>]a,a9<,a9-^X for'i>AXiR@Xi99( ] for';>AX;R@X;99( printf'NWdZtWdZtWdZtWdZnN,8'8'p9i(9;(, 8'8';9p(9i(,8'8'i9p(9;(,8'8'p9;(9i((X ^ ^ Ans)er/ < @ B = ? F D J < B F = D @ ? J < @ B = ? F D J < B F = D @ ? J

01p2anati!n/ 8'8'p9i(9;( is e,uivalent to pOiPO;P. <BF( main'( ] void swap'(X int 3><A,y>DX swap'U3,Uy(X printf'N3>Wd y>WdN,3,y(X ^ void swap'int 8a, int 8b( ] 8a 6> 8b, 8b 6> 8a, 8a 6> 8bX ^ Ans)er/ 3><A y>D 01p2anati!n/ :sing 6 like this is a way to swap two variables without using a temporary variable and that too in a single statement. #nside main'(, void swap'(X means that swap is a function that may take any number of arguments 'not no arguments( and returns nothing. So this doesn1t issue a compiler error by the call swap'U3,Uy(X that has two arguments.

?@

*his convention is historically due to pre7A!S# style 'referred to as _ernighan and $itchie style( style of function declaration. #n that style, the swap function will be defined as follows, void swap'( int 8a, int 8b ] 8a 6> 8b, 8b 6> 8a, 8a 6> 8bX ^ where the arguments follow the '(. So naturally the declaration for swap will look like, void swap'( which means the swap can take any number of arguments. <BD( main'( ] int i > -=FX int 8i4tr > UiX printf'NWd WdN, 8''char8(i4tr(, 8''char8(i4tr9<( (X ^ Ans)er/ << 01p2anati!n/ *he integer value -=F is stored in the memory as, AAAAAAA< AAAAAAA<, so the individual bytes are taken by casting it to char 8 and get printed. <BJ( main'( ] int i > -=DX int 8i4tr > UiX printf'NWd WdN, 8''char8(i4tr(, 8''char8(i4tr9<( (X ^ Ans)er/ -< 01p2anati!n/ *he integer value -=F can be represented in binary as, AAAAAAA< AAAAAAA<. $emember that the #!*2. machines are 0small7endian1 machines. $mall3endian means that the lower order .ytes are stored in the higher memory addresses and the higher order .ytes are stored in lower addresses. *he integer value -=D is stored in memory as5 AAAAAAA< AAAAAA<A. <=A( main'( ] int i>@AAX char 8ptr > UiX 899ptr>-X printf'NWdN,i(X
?B

^ Ans)er/ ==? 01p2anati!n/ *he integer value @AA in binary notation is5 AAAAAAA< AA<A<<AA. #t is stored in memory 'small7endian( as5 AA<A<<AA AAAAAAA<. $esult of the e3pression 899ptr > - makes the memory representation as5 AA<A<<AA AAAAAA<A. So the integer corresponding to it is AAAAAA<A AA<A<<AA >Q ==?. <=<( Yinclude Rstdio.hQ main'( ] char 8 str > NhelloNX char 8 ptr > strX char least > <-FX while '8ptr99( least > '8ptrRleast ( `8ptr 5leastX printf'NWdN,least(X ^ Ans)er/ A 01p2anati!n/ After 0ptr1 reaches the end of the string the value pointed by 0str1 is 0ZA1. So the value of 0str1 is less than that of 0least1. So the value of 0least1 finally is A. Declare an array of ! pointers to functions returning pointers to functions returning pointers to characters` Ans)er/ 'char8'8(' (( '8ptrO!P(' (X main'( ] struct student ] char nameO@APX struct date dobX ^studX struct date ] int day,month,yearX ^X scanf'NWsWdWdWdN, stud.rollno, Ustudent.dob.month, Ustudent.dob.year(X ^
?=

<=-(

<=@(

Ustudent.dob.day,

Ans)er/ Compiler 2rror5 :ndefined structure date 01p2anati!n/ #nside the struct definition of 0student1 the member of type struct date is given. *he compiler doesn1t have the definition of date structure 'forward reference is not allowed in C in this case( so it issues an error. <=B( main'( ] struct dateX struct student ] char nameO@APX struct date dobX ^studX struct date ] int day,month,yearX ^X scanf'NWsWdWdWdN, stud.rollno, Ustudent.dob.day, Ustudent.dob.month, Ustudent.dob.year(X ^ Ans)er/ Compiler 2rror5 :ndefined structure date 01p2anati!n/ Only declaration of struct date is available inside the structure definition of 0student1 but to have a variable of type struct date the definition of the structure is re,uired. <==( *here were <A records stored in [somefile.dat\ but the following program printed << names. Ehat went wrong` void main'( ] struct student ] char nameO@AP, rollnoO?PX ^studX /#.2 8fp > fopen'[somefile.dat\,\r\(X while'Sfeof'fp(( ] fread'Ustud, sizeof'stud(, < , fp(X puts'stud.name(X ^ ^ 01p2anati!n/

??

fread reads <A records and prints the names successfully. #t will return 2O/ only when fread tries to read another record and fails reading 2O/ 'and returning 2O/(. So it prints the last record again. After this only the condition feof'fp( becomes false, hence comes out of the while loop. <=?( #s there any difference between the two declarations, <. int foo'int 8arrOP( and -. int foo'int 8arrO-P( Ans)er/ !o 01p2anati!n/ /unctions can only pass pointers and not arrays. *he numbers that are allowed inside the OP is ;ust for more readability. So there is no difference between the two declarations. Ehat is the subtle error in the following code segment` void fun'int n, int arrOP( ] int 8p>AX int i>AX while'i99Rn( p > UarrOiPX 8p > AX ^ Ans)er 3 01p2anati!n/ #f the body of the loop never e3ecutes p is assigned no address. So p remains !:.. where 8p >A may result in problem 'may rise to runtime error [!:.. pointer assignment\ and terminate the program(. Ehat is wrong with the following code` int 8foo'( ] int 8s > malloc'sizeof'int(<AA(X assert's S> !:..(X return sX ^ Ans)er 3 01p2anati!n/ assert macro should be used for debugging and finding out bugs. *he check s S> !:.. is for errorKe3ception handling and for that assert shouldn1t be used. A plain if and the corresponding remedy statement has to be given. Ehat is the hidden bug with the following statement`

<=F(

<=D(

<=J(
?F

assert'val99 S> A(X Ans)er 3 01p2anati!n/ Assert macro is used for debugging and removed in release version. #n assert, the e3perssion involves side7effects. So the behavior of the code becomes different in case of debug version and the release version thus leading to a subtle bug. "u2e t! "e(e(6er/ !onFt use expressions that have side3effects in assert statements. <?A( void main'( ] int 8i > A3BAAX KK i points to the address BAA 8i > AX KK set the value of memory location pointed by iX ^ Ans)er/ :ndefined behavior 01p2anati!n/ *he second statement results in undefined behavior because it points to some location whose value may not be available for modification. Dhis type of pointer in which the non3availa.ility of the implementation of the referenced location is 'nown as Wincomplete typeW. Ydefine assert'cond( if'S'cond(( Z 'fprintf'stderr, Nassertion failed5 Ws, file Ws, line Wd ZnN,Ycond,Z MM/#.2MM,MM.#!2MM(, abort'(( void main'( ] int i > <AX if'i>>A( assert'i R <AA(X else printf'N*his statement becomes else for if in assert macroN(X ^ Answer5 !o output 01p2anati!n/ *he else part in which the printf is there becomes the else for if in the assert macro. )ence nothing is printed. *he solution is to use conditional operator instead of if statement, Ydefine assert'cond( ''cond(`'A(5 'fprintf 'stderr, Nassertion failed5 Z Ws, file Ws, line Wd ZnN,Ycond, MM/#.2MM,MM.#!2MM(, abort'((( !ote5 )owever this problem of [matching with nearest else\ cannot be solved by the usual method of placing the if statement inside a block like this,
?D

<?<(

Ydefine assert'cond( ] Z if'S'cond(( Z 'fprintf'stderr, Nassertion failed5 Ws, file Ws, line Wd ZnN,Ycond,Z MM/#.2MM,MM.#!2MM(, abort'(( Z ^ <?-( #s the following code legal` struct a ] int 3X struct a bX ^ Answer5 !o 01p2anati!n/ #s it not legal for a structure to contain a member that is of the same type as in this case. %ecause this will cause the structure declaration to be recursive without end. #s the following code legal` struct a ] int 3X struct a 8bX ^ Ans)er/ Hes. 01p2anati!n/ 8b is a pointer to type struct a and so is legal. *he compiler knows, the size of the pointer to a structure even before the size of the structure is determined'as you know the pointer to any type is of same size(. *his type of structures is known as 0self7referencing1 structure. #s the following code legal` typedef struct a ] int 3X a*ype 8bX ^a*ype Ans)er/ !o 01p2anati!n/ *he typename a*ype is not known at the point of declaring the structure 'forward references are not made for typedefs(. #s the following code legal`

<?@(

<?B(

<?=(
?J

typedef struct a a*ypeX struct a ] int 3X a*ype 8bX ^X Ans)er/ Hes 01p2anati!n/ *he typename a*ype is known at the point of declaring the structure, because it is already typedefined. <??( #s the following code legal` void main'( ] typedef struct a a*ypeX a*ype some+ariableX struct a ] int 3X a*ype 8bX ^X ^ Ans)er/ !o 01p2anati!n/ Ehen the declaration, typedef struct a a*ypeX is encountered body of struct a is not known. *his is known as 0incomplete types1. void main'( ] printf'[sizeof 'void 8( > Wd Zn[, sizeof' void 8((X printf'[sizeof 'int 8( > Wd Zn\, sizeof'int 8((X printf'[sizeof 'double 8( > Wd Zn\, sizeof'double 8((X printf'[sizeof'struct unknown 8( > Wd Zn\, sizeof'struct unknown 8((X ^ Ans)er / sizeof 'void 8( > sizeof 'int 8( > sizeof 'double 8( > sizeof'struct unknown 8( > 01p2anati!n/ *he pointer to any type is of same size.

<?F(

FA

<?D(

char inputStringO<AAP > ]A^X *o get string input from the keyboard which one of the following is better` <( gets'inputString( -( fgets'inputString, sizeof'inputString(, fp( Ans)er 3 01p2anati!n/ *he second one is better because gets'inputString( doesnTt know the size of the string passed and so, if a very big input 'here, more than <AA chars( the charactes will be written past the input string. Ehen fgets is used with stdin performs the same operation as gets but is safe. Ehich version do you prefer of the following two, <( printf'[Ws\,str(X KK or the more curt one -( printf'str(X Ans)er 3 01p2anati!n/ 4refer the first one. #f the str contains any format characters like Wd then it will result in a subtle bug. void main'( ] int i><A, ;>-X int 8ip> Ui, 8;p > U;X int k > 8ipK8;pX printf'[Wd\,k(X ^ Ans)er/ Compiler 2rror5 [:ne3pected end of file in comment started in line =\. 01p2anati!n/ *he programmer intended to divide two integers, but by the [ma3imum munch\ rule, the compiler treats the operator se,uence K and 8 as K8 which happens to be the starting of comment. *o force what is intended by the programmer, int k > 8ipK 8;pX KK give space e3plicity separating K and 8 KKor int k > 8ipK'8;p(X KK put braces to force the intention will solve the problem. void main'( ] char chX for'ch>AXchR><-FXch99( printf'[Wc Wd Zn[, ch, ch(X ^ Ans)er/ #mplementaion dependent

<?J(

<FA(

<F<(

F<

01p2anati!n/ *he char type may be signed or unsigned by default. #f it is signed then ch99 is e3ecuted after ch reaches <-F and rotates back to 7<-D. *hus ch is always smaller than <-F. <F-( #s this code legal` int 8ptrX ptr > 'int 8( A3BAAX Ans)er/ Hes 01p2anati!n/ *he pointer ptr will point at the integer in the memory location A3BAA. main'( ] char aOBP>N)2..ONX printf'NWsN,a(X ^ Ans)er/ Compiler error5 *oo many initializers 01p2anati!n/ *he array a is of size B but the string constant re,uires ? bytes to get stored. <FB( main'( ] char aOBP>N)2..NX printf'NWsN,a(X ^ Ans)er/ )2..WbSabSb```baaS 01p2anati!n/ *he character array has the memory ;ust enough to hold the string [)2..\ and doesnt have enough space to store the terminating null character. So it prints the )2.. correctly and continues to print garbage values till it accidentally comes across a !:.. character. <F=( main'( ] int a><A,8;X void 8kX ;>k>UaX ;99X k99X printf'NZn Wu Wu N,;,k(X ^
F-

<F@(

Ans)er/ Compiler error5 Cannot increment a void pointer 01p2anati!n/ +oid pointers are generic pointers and they can be used only when the type is not known and as an intermediate address storage type. !o pointer arithmetic can be done on it and you cannot apply indirection operator '8( on void pointers. <F?( main'( ] ] ] ^ printf'NWdN,i(X ^ printf'NWdN,i(X ^ int iX <FF( 4rintf can be implemented by using MMMMMMMMMM list. Ans)er/ +ariable length argument lists <FD( char 8some/un'( ] char 8temp > [string constantNX return tempX ^ int main'( ] puts'some/un'((X ^ Answer5 string constant 01p2anati!n5 *he program suffers no problem and gives the output correctly because the character constants are stored in codeKdata area and not allocated in stack, so this doesn1t lead to dangling pointers. <FJ( char 8some/un<'( ] char tempO P > [stringNX return tempX ^ char 8some/un-'( e3tern int iX int i>-AX const volatile unsigned i>@AX printf'NWdN,i(X

F@

] char tempO P > ]0s1, 0t1,1r1,1i1,1n1,1g1^X return tempX ^ int main'( ] puts'some/un<'((X puts'some/un-'((X ^ Answer5 "arbage values. 01p2anati!n5 %oth the functions suffer from the problem of dangling pointers. #n some/un<'( temp is a character array and so the space for it is allocated in heap and is initialized with character string [string\. *his is created dynamically as the function is called, so is also deleted dynamically on e3iting the function so the string data is not available in the calling function main'( leading to print some garbage values. *he function some/un-'( also suffers from the same problem but the problem can be easily identified in this case.

FB

C++ Aptitude and OOPS


C99 Aptitude and OO4S
!ote 5 All the programs are tested under *urbo C99 @.A, B.= and icrosoft +C99 ?.A compilers. #t is assumed that, 4rograms run under Eindows environment, *he underlying machine is an 3D? based system, 4rogram is compiled using *urbo CKC99 compiler. *he program output may depend on the information based on this assumptions 'for e3ample sizeof'int( >> - may be assumed(. <( class Sample ] public5 int 8ptrX Sample'int i( ] ptr > new int'i(X ^ aSample'( ] delete ptrX ^ void 4rint+al'( ] cout RR N*he value is N RR 8ptrX ^ ^X void Some/unc'Sample 3( ] cout RR NSay i am in some/unc N RR endlX ^ int main'( ] Sample s<> <AX Some/unc's<(X s<.4rint+al'(X ^ Ans)er/
F=

Say i am in some/unc !ull pointer assignment'$un7time error( 01p2anati!n5 As the ob;ect is passed by value to Some/unc the destructor of the ob;ect is called when the control returns from the function. So when 4rint+al is called it meets up with ptr that has been freed.*he solution is to pass the Sample ob;ect by reference to Some/unc5 void Some/unc'Sample U3( ] cout RR NSay i am in some/unc N RR endlX ^ because when we pass ob;ects by refernece that ob;ect is not destroyed. while returning from the function. -( Ehich is the parameter that is added to every non7static member function when it is called` Ans)er/ 0this1 pointer @( class base ] public5 int bvalX base'(] bval>AX^ ^X class deri5public base ] public5 int dvalX deri'(] dval><X^ ^X void Some/unc'base 8arr,int size( ] for'int i>AX iRsizeX i99,arr99( coutRRarr7QbvalX coutRRendlX ^ int main'( ] base %aseArrO=PX Some/unc'%aseArr,=(X deri DeriArrO=PX Some/unc'DeriArr,=(X
F?

^ Ans)er/ AAAAA A<A<A 01p2anati!n/ *he function Some/unc e3pects two arguments.*he first one is a pointer to an array of base class ob;ects and the second one is the sizeof the array.*he first call of some/unc calls it with an array of bae ob;ects, so it works correctly and prints the bval of all the ob;ects. Ehen Somefunc is called the second time the argument passed is the pointeer to an array of derived class ob;ects and not the array of base class ob;ects. %ut that is what the function e3pects to be sent. So the derived class pointer is promoted to base class pointer and the address is sent to the function. Some/unc'( knows nothing about this and ;ust treats the pointer as an array of base class ob;ects. So when arr99 is met, the size of base class ob;ect is taken into consideration and is incremented by sizeof'int( bytes for bval 'the deri class ob;ects have bval and dval as members and so is of size Q> sizeof'int(9sizeof'int( (. B( class base ] public5 void base/un'(] coutRRNfrom baseNRRendlX^ ^X class deri5public base ] public5 void base/un'(] coutRR Nfrom derivedNRRendlX^ ^X void Some/unc'base 8baseOb;( ] baseOb;7Qbase/un'(X ^ int main'( ] base baseOb;ectX Some/unc'UbaseOb;ect(X deri deriOb;ectX Some/unc'UderiOb;ect(X ^ Ans)er/ from base from base 01p2anati!n/ As we have seen in the previous case, Some/unc e3pects a pointer to a base class. Since a pointer to a derived class ob;ect is passed, it treats the argument only as a base class pointer and the corresponding base function is called.
FF

=( class base ] public5 virtual void base/un'(] coutRRNfrom baseNRRendlX^ ^X class deri5public base ] public5 void base/un'(] coutRR Nfrom derivedNRRendlX^ ^X void Some/unc'base 8baseOb;( ] baseOb;7Qbase/un'(X ^ int main'( ] base baseOb;ectX Some/unc'UbaseOb;ect(X deri deriOb;ectX Some/unc'UderiOb;ect(X ^ Ans)er/ from base from derived 01p2anati!n/ $emember that base/unc is a virtual function. *hat means that it supports run7 time polymorphism. So the function corresponding to the derived class ob;ect is called. void main'( ] int a, 8pa, UraX pa > UaX ra > aX cout RRNa>NRRa RRN8pa>NRR8pa RRNraNRRra X ^ K8 Answer 5 Compiler 2rror5 TraT,reference must be initialized 23planation 5 4ointers are different from references. One of the main differences is that the pointers can be both initialized and assigned, whereas references can only be initialized. So this code issues an error. 8K
FD

const int size > =X void print'int 8ptr( ] coutRRptrOAPX ^ void print'int ptrOsizeP( ] coutRRptrOAPX ^ void main'( ] int aOsizeP > ]<,-,@,B,=^X int 8b > new int'size(X print'a(X print'b(X ^ K8 Answer5 Compiler 2rror 5 function Tvoid print'int 8(T already has a body 23planation5 Arrays cannot be passed to functions, only pointers 'for arrays, base addresses( can be passed. So the arguments int 8ptr and int prtOsizeP have no difference as function arguments. #n other words, both the functoins have the same signature and so cannot be overloaded. 8K class some] public5 asome'( ] coutRRNsomeTs destructorNRRendlX ^ ^X void main'( ] some sX s.asome'(X ^ K8 Answer5 someTs destructor someTs destructor
FJ

23planation5 Destructors can be called e3plicitly. )ere Ts.asome'(T e3plicitly calls the destructor of TsT. Ehen main'( returns, destructor of s is called again, hence the result. 8K Yinclude Riostream.hQ class fig-d ] int dim<X int dim-X public5 fig-d'( ] dim<>=X dim->?X^ virtual void operatorRR'ostream U rhs(X ^X void fig-d55operatorRR'ostream Urhs( ] rhs RRthis7Qdim<RRN NRRthis7Qdim-RRN NX ^ K8class fig@d 5 public fig-d ] int dim@X public5 fig@d'( ] dim@>FX^ virtual void operatorRR'ostream Urhs(X ^X void fig@d55operatorRR'ostream Urhs( ] fig-d55operator RR'rhs(X rhsRRthis7Qdim@X ^ 8K void main'( ] fig-d ob;<X KK fig@d ob;-X KK ^
DA

ob;< RR coutX ob;- RR coutX

K8 Answer 5 =? 23planation5 #n this program, the RR operator is overloaded with ostream as argument. *his enables the TcoutT to be present at the right7hand7side. !ormally, TcoutT is implemented as global function, but it doesnTt mean that TcoutT is not possible to be overloaded as member function. Overloading RR as virtual member function becomes handy when the class in which it is overloaded is inherited, and this becomes available to be overrided. *his is as opposed to global friend functions, where friendTs are not inherited. 8K class opOverload] public5 bool operator>>'opOverload temp(X ^X bool opOverload55operator>>'opOverload temp(] if'8this >> temp (] coutRRN*he both are same ob;ectsZnNX return trueX ^ else] coutRRN*he both are differentZnNX return falseX ^ ^ void main'(] opOverload a<, a-X a<> >a-X ^ Answer 5 $untime 2rror5 Stack Overflow 23planation 5 Cust like normal functions, operator functions can be called recursively. *his program ;ust illustrates that point, by calling the operator >> function recursively, leading to an infinite loop. class comple3] double reX double imX
D<

public5 comple3'( 5 re'<(,im'A.=( ]^ bool operator>>'comple3 Urhs(X operator int'(]^ ^X bool comple355operator >> 'comple3 Urhs(] if''this7Qre >> rhs.re( UU 'this7Qim >> rhs.im(( return trueX else return falseX ^ int main'(] comple3 c<X coutRR c<X ^ Answer 5 "arbage value 23planation5 *he programmer wishes to print the comple3 ob;ect using output re7direction operator,which he has not defined for his lass.%ut the compiler instead of giving an error sees the conversion function and converts the user defined ob;ect to standard ob;ect and prints some garbage value. class comple3] double reX double imX public5 comple3'( 5 re'A(,im'A( ]^ comple3'double n( ] re>n,im>nX^X comple3'int m,int n( ] re>m,im>nX^ void print'( ] coutRRreX coutRRimX^ ^X void main'(] comple3 c@X double i>=X c@ > iX c@.print'(X ^ Answer5
D-

=,= 23planation5 *hough no operator> function taking comple3, double is defined, the double on the rhs is converted into a temporary ob;ect using the single argument constructor taking double and assigned to the lvalue. void main'( ] int a, 8pa, UraX pa > UaX ra > aX cout RRNa>NRRa RRN8pa>NRR8pa RRNraNRRra X ^ Answer 5 Compiler 2rror5 TraT,reference must be initialized 23planation 5 4ointers are different from references. One of the main differences is that the pointers can be both initialized and assigned, whereas references can only be initialized. So this code issues an error. 4r, it :!urse28 <( Determine the output of the TC99T Codelet. class base ] public 5 out'( ] coutRRNbase NX ^ ^X class deri] public 5 out'( ] coutRRNderi NX ^ ^X void main'( ] deri dpO@PX base 8bp > 'base8(dpX for 'int i>AX iR@Xi99( 'bp99(7Qout'(X ^
D@

-( Custify the use of virtual constructors and destructors in C99. @( 2ach C99 ob;ect possesses the B member fns,'which can be declared by the programmer e3plicitly or by the implementation if they are not available(. Ehat are those B functions` B( Ehat is wrong with this class declaration` class something ] char 8strX public5 something'(] st > new charO<APX ^ asomething'( ] delete strX ^ ^X =( #nheritance is also known as 77777777 relationship. Containership as relationship. MMMMMMMM

?( Ehen is it necessary to use member7wise initialization list 'also known as header initialization list( in C99` F( Ehich is the only operator in C99 which can be overloaded but !O* inherited. D( #s there anything wrong with this C99 class declaration` class temp ] int value<X mutable int value-X public 5 void fun'int val( const] ''temp8( this(7Qvalue< > <AX value- > <AX ^ ^X

DB

1. What is a modifier? Ans)er/ A modifier, also called a modifying function is a member function that changes the value of at least one data member. #n other words, an operation that modifies the state of an ob;ect. odifiers are also known as 0mutators1. 2. What is an accessor? Ans)er/ An accessor is a class operation that does not modify the state of an ob;ect. *he accessor functions need to be declared as const operations 3. !ifferentiate .etween a template class and class template. Ans)er/
4e(p2ate c2ass/

A generic definition or a parameterized class not instantiated until the client provides the needed information. #t1s ;argon for plain templates.
C2ass te(p2ate/

A class template specifies how individual classes can be constructed much like the way a class specifies how individual ob;ects can be constructed. #t1s ;argon for plain classes. *. When does a name clash occur? Ans)er/ A name clash occurs when a name is defined in more than one place. /or e3ample., two different class libraries could give two different classes the same name. #f you try to use many class libraries at the same time, there is a fair chance that you will be unable to compile or link the program because of name clashes. -. !efine namespace. Ans)er/ #t is a feature in c99 to minimize name collisions in the global name space. *his namespace keyword assigns a distinct name to a library that allows other libraries to use the same identifier names without creating any name collisions. /urthermore, the compiler uses the namespace signature for differentiating the definitions. 0. What is the use of XusingF declaration. Ans)er/ A using declaration makes it possible to use a name from a namespace without the scope operator. 5. What is an +terator class? Ans)er/ A class that is used to traverse through the ob;ects maintained by a container class. *here are five categories of iterators5 input iterators, output iterators,
D=

forward iterators, bidirectional iterators, random access. An iterator is an entity that gives access to the contents of a container ob;ect without violating encapsulation constraints. Access to the contents is granted on a one7at7 a7time basis in order. *he order can be storage order 'as in lists and ,ueues( or some arbitrary order 'as in array indices( or according to some ordering relation 'as in an ordered binary tree(. *he iterator is a construct, which provides an interface that, when called, yields either the ne3t element in the container, or some value denoting the fact that there are no more elements to e3amine. #terators hide the details of access to and update of the elements of a container class. *he simplest and safest iterators are those that permit read7only access to the contents of a container class. *he following code fragment shows how an iterator might appear in code5 contMiter5>new contMiterator'(X 35>contMiter.ne3t'(X while 3K>none do ... s'3(X ... 35>contMiter.ne3t'(X endX #n this e3ample, contMiter is the name of the iterator. #t is created on the first line by instantiation of contMiterator class, an iterator class defined to iterate over some container class, cont. Succesive elements from the container are carried to 3. *he loop terminates when 3 is bound to some empty value. ')ere, none(#n the middle of the loop, there is s'3( an operation on 3, the current element from the container. *he ne3t element of the container is obtained at the bottom of the loop. ?. List out some of the EE!"#$ availa.le. Ans)er/ "2 S*O!2KO4A. of "emstone systems. O!*OS of Ontos. Ob;ectivity of Ob;ectivity inc. +ersant of +ersant ob;ect technology. Ob;ect store of Ob;ect Design. A$D2!* of A$D2!* software. 4O2* of 4O2* software. 1@. List out some of the o.ject3oriented methodologies. Ans)er/ Ob;ect Oriented Development 'OOD( '%ooch <JJ<,<JJB(. Ob;ect Oriented Analysis and Design 'OOAKD( 'Coad and Hourdon <JJ<(. Ob;ect odelling *echni,ues 'O *( '$umbaugh <JJ<(. Ob;ect Oriented Software 2ngineering 'Ob;ectory( 'Cacobson <JJ-(.
D?

Ob;ect Oriented Analysis 'OOA( 'Shlaer and *he /usion ethod 'Coleman <JJ<(.

ellor <JJ-(.

11. What is an incomplete type? Ans)er/ #ncomplete types refers to pointers in which there is non availability of the implementation of the referenced location or it points to some location whose value is not available for modification. 01a(p2e/ int 8i>A3BAA KK i points to address BAA 8i>AX KKset the value of memory location pointed by i. #ncomplete types are otherwise called uninitialized pointers. 12. What is a dangling pointer? Ans)er/ A dangling pointer arises when you use the address of an ob;ect after its lifetime is over. *his may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed. 13. !ifferentiate .etween the message and method. Ans)er/ $essa+e $et5!d Ob;ects communicate by sending messages 4rovides response to a message. to each other. A message is sent to invoke a method. #t is an implementation of an operation. 1*. What is an adaptor class or Wrapper class? Ans)er/ A class that has no functionality of its own. #ts member functions hide the use of a third party software component or an ob;ect with the non7compatible interface or a non7 ob;ect7 oriented implementation. 1-. What is a &ull o.ject? Ans)er/ #t is an ob;ect of some class whose purpose is to indicate that a real ob;ect of that class does not e3ist. One common use for a null ob;ect is a return value from a member function that is supposed to return an ob;ect with some specified properties but cannot find such an ob;ect. 10. What is class invariant? Ans)er/ A class invariant is a condition that defines all valid states for an ob;ect. #t is a logical condition to ensure the correct working of a class. Class invariants must hold when an ob;ect is created, and they must be preserved under all operations of the class. #n
DF

particular all class invariants are both preconditions and post7conditions for all operations or member functions of the class. 15. What do you mean .y $tac' unwinding? Ans)er/ #t is a process during e3ception handling when the destructor is called for all local ob;ects between the place where the e3ception was thrown and where it is caught. 17. !efine precondition and post3condition to a mem.er function. Ans)er/ Prec!nditi!n/ A precondition is a condition that must be true on entry to a member function. A class is used correctly if preconditions are never false. An operation is not responsible for doing anything sensible if its precondition fails to hold. /or e3ample, the interface invariants of stac' class say nothing about pushing yet another element on a stack that is already full. Ee say that isful24 is a precondition of the push operation. P!st-c!nditi!n/ A post7condition is a condition that must be true on e3it from a member function if the precondition was valid on entry to that function. A class is implemented correctly if post7conditions are never false. /or e3ample, after pushing an element on the stack, we know that isempty24 must necessarily hold. *his is a post7condition of the push operation. 1?. What are the conditions that have to .e met for a condition to .e an invariant of the class? Ans)er/ *he condition should hold at the end of every constructor. *he condition should hold at the end of every mutator'non7const( operation. 2@. What are proxy o.jects? Ans)er/ Ob;ects that stand for other ob;ects are called pro3y ob;ects or surrogates. 01a(p2e/ templateRclass *Q class Array-D ] public5 class Array<D ] public5 *U operatorOP 'int inde3(X const *U operatorOP 'int inde3( constX ... ^X
DD

Array<D operatorOP 'int inde3(X const Array<D operatorOP 'int inde3( constX ... ^X *he following then becomes legal5 Array-DRfloatQdata'<A,-A(X ........ coutRRdataO@PO?PX KK fine )ere dataO@P yields an Array<D ob;ect and the operator OP invocation on that ob;ect yields the float in position'@,?( of the original two dimensional array. Clients of the Array-D class need not be aware of the presence of the Array<D class. Ob;ects of this latter class stand for one7dimensional array ob;ects that, conceptually, do not e3ist for clients of Array-D. Such clients program as if they were using real, live, two7dimensional arrays. 2ach Array<D ob;ect stands for a one7dimensional array that is absent from a conceptual model used by the clients of Array-D. #n the above e3ample, Array<D is a pro3y class. #ts instances stand for one7dimensional arrays that, conceptually, do not e3ist. 21. &ame some pure o.ject oriented languages. Ans)er/ Smalltalk, Cava, 2iffel, Sather. 22. &ame the operators that cannot .e overloaded. Ans)er/ sizeof . .8 .7Q 55 `5 23. What is a node class? Ans)er/ A node class is a class that, relies on the base class for services and implementation, provides a wider interface to te users than its base class, relies primarily on virtual functions in its public interface depends on all its direct and indirect base class can be understood only in the conte3t of the base class can be used as base for further derivation can be used to create ob;ects. A node class is a class that has added new services or functionality beyond the services inherited from its base class. 2*. What is an orthogonal .ase class? Ans)er/
DJ

#f two base classes have no overlapping methods or data they are said to be independent of, or orthogonal to each other. Orthogonal in the sense means that two classes operate in different dimensions and do not interfere with each other in any way. *he same derived class may inherit such classes with no difficulty. 2-. What is a container class? What are the types of container classes? Ans)er/ A container class is a class that is used to hold ob;ects in memory or e3ternal storage. A container class acts as a generic holder. A container class has a predefined behavior and a well7known interface. A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of ob;ects in memory. Ehen a container class contains a group of mi3ed ob;ects, the container is called a heterogeneous containerX when the container is holding a group of ob;ects that are all the same, the container is called a homogeneous container. 20. What is a protocol class? Ans)er/ An abstract class is a protocol class if5 it neither contains nor inherits from classes that contain member data, non7virtual functions, or private 'or protected( members of any kind. it has a non7inline virtual destructor defined with an empty implementation, all member functions other than the destructor including inherited functions, are declared pure virtual functions and left undefined. 25. What is a mixin class? Ans)er/ A class that provides some but not all of the implementation for a virtual base class is often called mi3in. Derivation done ;ust for the purpose of redefining the virtual functions in the base classes is often called mi3in inheritance. i3in classes typically donTt share common bases. 27. What is a concrete class? Ans)er/ A concrete class is used to define a useful ob;ect that can be instantiated as an automatic variable on the program stack. *he implementation of a concrete class is defined. *he concrete class is not intended to be a base class and no attempt to minimize dependency on other classes in the implementation or behavior of the class. 2?.What is the handle class? Ans)er/ A handle is a class that maintains a pointer to an ob;ect that is programmatically accessible through the public interface of the handle class. 01p2anati!n/ #n case of abstract classes, unless one manipulates the ob;ects of these classes through pointers and references, the benefits of the virtual functions are lost. :ser code may become dependent on details of implementation classes because an abstract type
JA

cannot be allocated statistically or on the stack without its size being known. :sing pointers or references implies that the burden of memory management falls on the user. Another limitation of abstract class ob;ect is of fi3ed size. Classes however are used to represent concepts that re,uire varying amounts of storage to implement them. A popular techni,ue for dealing with these issues is to separate what is used as a single ob;ect in two parts5 a handle providing the user interface and a representation holding all or most of the ob;ectTs state. *he connection between the handle and the representation is typically a pointer in the handle. Often, handles have a bit more data than the simple representation pointer, but not much more. )ence the layout of the handle is typically stable, even when the representation changes and also that handles are small enough to move around relatively freely so that the user needn1t use the pointers and the references. 3@. What is an action class? Ans)er/ *he simplest and most obvious way to specify an action in C99 is to write a function. )owever, if the action has to be delayed, has to be transmitted TelsewhereT before being performed, re,uires its own data, has to be combined with other actions, etc then it often becomes attractive to provide the action in the form of a class that can e3ecute the desired action and provide other services as well. anipulators used with iostreams is an obvious e3ample. 01p2anati!n/ A common form of action class is a simple class containing ;ust one virtual function. class Action ] public5 virtual int doMit' int (>AX virtual aAction' (X ^ "iven this, we can write code say a member that can store actions for later e3ecution without using pointers to functions, without knowing anything about the ob;ects involved, and without even knowing the name of the operation it invokes. /or e3ample5 class writeMfile 5 public Action ] /ileU fX public5 int doMit'int( ] return fwrite' (.suceed' (X ^ ^X class errorMmessage5 public Action ] responseMbo3 db'message.cstr' (,NContinueN,NCancelN,N$etryN(X switch 'db.getresponse' ((
J<

] case A5 return AX case <5 abort'(X case -5 currentMoperation.redo' (Xreturn <X ^ ^X A user of the Action class will be completely isolated from any knowledge of derived classes such as writeMfile and errorMmessage. 31. When can you tell that a memory lea' will occur? Ans)er/ A memory leak occurs when a program loses the ability to free a block of dynamically allocated memory. 32.What is a parameteriCed type? Ans)er/ A template is a parameterized construct or type containing generic code that can use or manipulate any type. #t is called parameterized because an actual type is a parameter of the code body. 4olymorphism may be achieved through parameterized types. *his type of polymorphism is called parameteric polymorphism. 4arameteric polymorphism is the mechanism by which the same code is used on different types passed as parameters. 33. !ifferentiate .etween a deep copy and a shallow copy? Ans)er/ Deep copy involves using the contents of one ob;ect to create another instance of the same class. #n a deep copy, the two ob;ects may contain the same information but the target ob;ect will have its own buffers and resources. *he destruction of either ob;ect will not affect the remaining ob;ect. *he overloaded assignment operator would create a deep copy of ob;ects. Shallow copy involves copying the contents of one ob;ect into another instance of the same class thus creating a mirror image. Owing to straight copying of references and pointers, the two ob;ects will share the same e3ternally contained contents of the other ob;ect to be unpredictable. 01p2anati!n/ :sing a copy constructor we simply copy the data values member by member. *his method of copying is called shallow copy. #f the ob;ect is a simple class, comprised of built in types and no pointers this would be acceptable. *his function would use the values and the ob;ects and its behavior would not be altered with a shallow copy, only the addresses of pointers that are members are copied and not the value the address is pointing to. *he data values of the ob;ect would then be inadvertently altered by the function. Ehen the function goes out of scope, the copy of the ob;ect with all its data is popped off the stack.

J-

#f the ob;ect has any pointers a deep copy needs to be e3ecuted. Eith the deep copy of an ob;ect, memory is allocated for the ob;ect in free store and the elements pointed to are copied. A deep copy is used for ob;ects that are returned from a function. 3*. What is an opa/ue pointer? Ans)er/ A pointer is said to be opa,ue if the definition of the type to which it points to is not included in the current translation unit. A translation unit is the result of merging an implementation file with all its headers and header files. 3-. What is a smart pointer? Ans)er/ A smart pointer is an ob;ect that acts, looks and feels like a normal pointer but offers more functionality. #n C99, smart pointers are implemented as template classes that encapsulate a pointer and override standard pointer operators. *hey have a number of advantages over regular pointers. *hey are guaranteed to be initialized as either null pointers or pointers to a heap ob;ect. #ndirection through a null pointer is checked. !o delete is ever necessary. Ob;ects are automatically freed when the last pointer to them has gone away. One significant problem with these smart pointers is that unlike regular pointers, they donTt respect inheritance. Smart pointers are unattractive for polymorphic code. "iven below is an e3ample for the implementation of smart pointers.
01a(p2e/

template Rclass GQ class smartMpointer ] public5 smartMpointer'(X smartMpointer'const GU 3( GU operator 8' (X const GU operator8' ( constX G8 operator7Q'( constX

KK makes a null pointer KK makes pointer to copy of 3

smartMpointer'const smartMpointer RGQ U(X const smartMpointer RGQ U operator >'const smartMpointerRGQU(X asmartMpointer'(X private5 KK... ^X *his class implement a smart pointer to an ob;ect of type G. *he ob;ect itself is located on the heap. )ere is how to use it5 smartMpointer RemployeeQ p> employee'N)arrisN,<@@@(X .ike other overloaded operators, p will behave like a regular pointer, coutRR8pX p7QraiseMsalary'A.=(X 30. What is reflexive association?
J@

Ans)er/ *he Tis7aT is called a refle3ive association because the refle3ive association permits classes to bear the is7a association not only with their super7classes but also with themselves. #t differs from a Tspecializes7fromT as Tspecializes7fromT is usually used to describe the association between a super7class and a sub7class. /or e3ample5 4rinter is7a printer. 35. What is slicing? Ans)er/ Slicing means that the data added by a subclass are discarded when an ob;ect of the subclass is passed or returned by value or from a function e3pecting a base class ob;ect. 01p2anati!n/ Consider the following class declaration5 class base ] ... baseU operator >'const baseU(X base 'const baseU(X ^ void fun' ( ] base e>mX e>mX ^ As base copy functions donTt know anything about the derived only the base part of the derived is copied. *his is commonly referred to as slicing. One reason to pass ob;ects of classes in a hierarchy is to avoid slicing. Other reasons are to preserve polymorphic behavior and to gain efficiency. 37. What is name mangling? Ans)er/ !ame mangling is the process through which your c99 compilers give each function in your program a uni,ue name. #n C99, all programs have at7least a few functions with the same name. !ame mangling is a concession to the fact that linker always insists on all function names being uni,ue.
01a(p2e/

#n general, member names are made uni,ue by concatenating the name of the member with that of the class e.g. given the declaration5 class %ar ] public5 int ivalX ... ^X ival becomes something like5 KK a possible member name mangling
JB

ivalMM@%ar Consider this derivation5 class /oo 5 public %ar ] public5 int ivalX ... ^ *he internal representation of a /oo ob;ect is the concatenation of its base and derived class members. KK 4seudo C99 code KK #nternal representation of /oo class /oo ] public5 int ivalMM@%arX int ivalMM@/ooX ... ^X :nambiguous access of either ival members is achieved through name mangling. ember functions, because they can be overloaded, re,uire an e3tensive mangling to provide each with a uni,ue name. )ere the compiler generates the same name for the two overloaded instances'*heir argument lists make their instances uni,ue(. 3?. What are proxy o.jects? Ans)er/ Ob;ects that points to other ob;ects are called pro3y ob;ects or surrogates. #ts an ob;ect that provides the same interface as its server ob;ect but does not have any functionality. During a method invocation, it routes data to the true server ob;ect and sends back the return value to the ob;ect. *@. !ifferentiate .etween declaration and definition in ,88. Ans)er/ A declaration introduces a name into the programX a definition provides a uni,ue description of an entity 'e.g. type, instance, and function(. Declarations can be repeated in a given scope, it introduces a name in a given scope. *here must be e3actly one definition of every ob;ect, function or class used in a C99 program. A declaration is a definition unless5 it declares a function without specifying its body, it contains an e3tern specifier and no initializer or function body, it is the declaration of a static class data member without a class definition, it is a class name definition, it is a typedef declaration. A definition is a declaration unless5 it defines a static class data member, it defines a non7inline member function.
J=

*1. What is cloning? Ans)er/ An ob;ect can carry out copying in two ways i.e. it can set itself to be a copy of another ob;ect, or it can return a copy of itself. *he latter process is called cloning. *2. !escri.e the main characteristics of static functions. Ans)er/ *he main characteristics of static functions include, #t is without the a this pointer, #t canTt directly access the non7static members of its class #t canTt be declared const, volatile or virtual. #t doesnTt need to be invoked through an ob;ect of its class, although for convenience, it may. *3. Will the inline function .e compiled as the inline function always? Yustify. Ans)er/ An inline function is a re,uest and not a command. )ence it wonTt be compiled as an inline function always. 01p2anati!n/ #nline7e3pansion could fail if the inline function contains loops, the address of an inline function is used, or an inline function is called in a comple3 e3pression. *he rules for inlining are compiler dependent. **. !efine a way other than using the 'eyword inline to ma'e a function inline. Ans)er/ *he function must be defined inside the class. *-. )ow can a W::W operator .e used as unary operator? Ans)er/ *he scope operator can be used to refer to members of the global namespace. %ecause the global namespace doesn1t have a name, the notation 55 member7name refers to a member of the global namespace. *his can be useful for referring to members of global namespace whose names have been hidden by names declared in nested local scope. :nless we specify to the compiler in which namespace to search for a declaration, the compiler simple searches the current scope, and any scopes in which the current scope is nested, to find the declaration for the name. *0. What is placement new? Ans)er/ Ehen you want to call a constructor directly, you use the placement new. Sometimes you have some raw memory thatTs already been allocated, and you need to construct an ob;ect in the memory you have. Operator newTs special version placement new allows you to do it. class Eidget ] public 5
J?

Eidget'int widgetsize(X ... Eidget8 ConstructMwidgetMintMbuffer'void 8buffer,int widgetsize( ] return new'buffer( Eidget'widgetsize(X ^ ^X *his function returns a pointer to a Eidget ob;ect thatTs constructed within the buffer passed to the function. Such a function might be useful for applications using shared memory or memory7mapped #KO, because ob;ects in such applications must be placed at specific addresses or in memory allocated by special routines. 0012 1. What do you mean .y analysis and design? 6nalysis: %asically, it is the process of determining what needs to be done before how it should be done. #n order to accomplish this, the developer refers the e3isting systems and documents. So, simply it is an art of discovery. !esign: #t is the process of adoptingKchoosing the one among the many, which best accomplishes the users needs. So, simply, it is compromising mechanism. 2. What are the steps involved in designing? %efore getting into the design the designer should go through the S$S prepared by the System Analyst. *he main tasks of design are Architectural Design and Detailed Design. #n Architectural Design we find what are the main modules in the problem domain. #n Detailed Design we find what should be done within each module. 3. What are the main underlying concepts of o.ject orientation? Ob;ects, messages, class, inheritance and polymorphism are the main concepts of ob;ect orientation. *. What do u meant .y K$"+K of an o.ject? S%# stands for State, %ehavior and #dentity. Since every ob;ect has the above three. $tate: #t is ;ust a value to the attribute of an ob;ect at a particular time. "ehaviour5 #t describes the actions and their reactions of that ob;ect. +dentity5 An ob;ect has an identity that characterizes its own e3istence. *he identity makes it possible to distinguish any ob;ect in an unambiguous way, and independently
JF

from its state. -. !ifferentiate persistent ( non3persistent o.jects? 4ersistent refers to an ob;ectTs ability to transcend time or space. A persistent ob;ect storesKsaves its state in a permanent storage system with out losing the information represented by the ob;ect. A non7persistent ob;ect is said to be transient or ephemeral. %y default ob;ects are considered as non7persistent. 0. What do you meant .y active and passive o.jects? Active ob;ects are one which instigate an interaction which owns a thread and they are responsible for handling control to other ob;ects. #n simple words it can be referred as client. 4assive ob;ects are one, which passively waits for the message to be processed. #t waits for another ob;ect that re,uires its services. #n simple words it can be referred as server. Diagram5 client server 'Active( '4assive( 5. What is meant .y software development method` Software development method describes how to model and build software systems in a reliable and reproducible way. *o put it simple, methods that are used to represent onesT thinking using graphical notations. 7. What are models and meta models? #odel: +t is a complete description of something 'i.e. system(. #eta model: #t describes the model elements, synta3 and semantics of the notation that allows their manipulation. ?. What do you meant .y static and dynamic modeling? Static modeling is used to specify structure of the ob;ects that e3ist in the problem domain. *hese are e3pressed using class, o.ject and Q$1,6$1 diagrams. %ut Dynamic modeling refers representing the ob;ect interactions during runtime. #t is represented by se/uence, activity, colla.oration and statechart diagrams. 1@. )ow to represent the interaction .etween the modeling elements? #odel element is ;ust a notation to represent '"raphically( the entities that e3ist in the problem domain. e.g. for modeling element is class notation, ob;ect notation etc. $elationships are used to represent the interaction between the modeling elements. *he following are the $elationships.
JD

6ssociation: #tsT ;ust a semantic connection two classes. e.g.5 uses class A class % 6ggregation: #tsT the relationship between two classes which are related in the fashion that master and slave. *he master takes full rights than the slave. Since the slave works under the master. #t is represented as line with diamond in the master area. e35 car contains wheels, etc. car car wheels

,ontainment: *his relationship is applied when the part contained with in the whole part, dies when the whole part dies. #t is represented as darked diamond at the whole part. e3ample5 class A] KKsome code ^X class % ] A aaX KK an ob;ect of class AX KK some code for class %X ^X #n the above e3ample we see that an ob;ect of class A is instantiated with in the class %. so the ob;ect class A dies when the ob;ect class % dies.we can represnt it in diagram like this. class A class %

=eneraliCation: *his relationship used when we want represents a class, which captures the common states of ob;ects of different classes. #t is represented as arrow line pointed at the class, which has captured the common states. class A

class %

class C

!ependency: #t is the relationship between dependent and independent classes. Any


JJ

change in the independent class will affect the states of the dependent class. D#A"$A 5 class A class % 11. Why generaliCation is very strong? 2ven though "eneralization satisfies Structural, #nterface, %ehaviour properties. #t is mathematically very strong, as it is Antisymmetric and *ransitive. 6ntisymmetric: employee is a person, but not all persons are employees. athematically all As1 are %, but all %s1 not A. Dransitive: A>Q%, %>Qc then A>Qc. A. Salesman. %. 2mployee. C. 4erson. *ote: All the other relationships satisfy all the properties like Structural properties, #nterface properties, %ehaviour properties. 12. !ifferentiate 6ggregation and containment? Aggregation is the relationship between the whole and a part. Ee can addKsubtract some properties in the part 'slave( side. #t wonTt affect the whole part. %est e3ample is Car, which contains the wheels and some e3tra parts. 2ven though the parts are not there we can call it as car. %ut, in the case of containment the whole part is affected when the part within that got affected. *he human body is an apt e3ample for this relationship. Ehen the whole body dies the parts 'heart etc( are died. 13. ,an lin' and 6ssociation applied interchangea.ly? !o, Hou cannot apply the link and Association interchangeably. Since link is used represent the relationship between the two ob;ects. %ut Association is used represent the relationship between the two classes. link 55 student5Abhilash course5 CA Association55 student course 1*. what is meant .y Kmethod3warsK? %efore <JJB there were different methodologies like $umbaugh, %ooch, Cacobson, eyer etc who followed their own notations to model the systems. *he developers were in a dilemma to choose the method which best accomplishes their needs. *his particular span was called as Nmethod7warsN 1-. Whether unified method and unified modeling language are same or different? :nified method is convergence of the $umbaugh and %ooch. :nified modeling lang. is the fusion of $umbaugh, %ooch and Cacobson as well as %etrand eyer 'whose contribution is Nse,uence diagramN(. #tsT the superset of all the methodologies. 10. Who were the three famous amigos and what was their contri.ution to the o.ject community?
<AA

*he *hree amigos namely, Yames um.augh 2E#D4: A veteran in analysis who came up with an idea about the ob;ects and their $elationships 'in particular Associations(. =rady "ooch: A veteran in design who came up with an idea about partitioning of systems into subsystems. +var Yaco.son 2E.jectory4: *he father of :S2CAS2S, who described about the user and system interaction. 15. !ifferentiate the class representation of "ooch% um.augh and Q#L? #f you look at the class representaiton of $umbaugh and : ., #t is some what similar and both are very easy to draw. Represent'tion: 03T U34. 2i'5r'm:

%ooch5 #n this method classes are represented as NCloudsN which are not very easy to draw as for as the developerTs view is concern. 2i'5r'm:

17. What is an Q$1,6$1? Why it is needed? A :se Case is a description of a set of se,uence of actions that a system performs that yields an observable result of value to a particular action. #n SSAD process R>Q #n OOAD :S2CAS2. #t is represented elliptically. Represent'tion:

1?. Who is an 6ctor? An Actor is someone or something that must interact with the system.#n addition to that an Actor initiates the process'that is :S2CAS2(. #t is represented as a stickman like this. 2i'5r'm:

<A<

2@. What is guard condition? "uard condition is one, which acts as a firewall. *he access from a particular ob;ect can be made only when the particular condition is met. /or 23ample, customer check customer number A* . )ere the ob;ect on the customer accesses the A* facility only when the guard condition is met. 21. !ifferentiate the following notations? +: :o.j1 :o.j2 ++: :o.j1 :o.j2

#n the above representation #, ob;< sends message to ob;-. %ut in the case of ## the data is transferred from ob;< to ob;-. 22. Q$1,6$1 is an implementation independent notation. )ow will the designer give the implementation details of a particular Q$1,6$1 to the programmer? *his can be accomplished by specifying the relationship called Nrefinement\ which talks about the two different abstraction of the same thing. Or e3ample, calculate pay calculate class< class- class@ 23. $uppose a class acts an 6ctor in the pro.lem domain% how to represent it in the static model? #n this scenario you can use [stereotype\. Since stereotype is ;ust a string that gives e3tra semantic to the particular entityKmodel element. #t is given with in the RR QQ. class A RR ActorQQ attributes methods. 2*. Why does the function arguments are called as KsignaturesK? *he arguments distinguish functions with the same name 'functional polymorphism(. *he name alone does not necessarily identify a uni,ue function. )owever, the name and its arguments 'signatures( will uni,uely identify a function. #n real life we see suppose, in class there are two guys with same name, but they can be easily identified by their signatures. *he same concept is applied here.
<A-

e35 class person ] public5 char getse3'(X void setse3'char(X void setse3'int(X ^X #n the above e3ample we see that there is a function setse3'( with same name but with different signature.

<A@

Quantitative Aptitude
Luantitative Aptitude
01ercise 1 S!2ve t5e 8!22!)in+ and c5ec* )it5 t5e ans)ers +iven at t5e end. <. #t was calculated that F= men could complete a piece of work in -A days. Ehen work was scheduled to commence, it was found necessary to send -= men to another pro;ect. )ow much longer will it take to complete the work` A student divided a number by -K@ when he re,uired to multiply by @K-. Calculate the percentage of error in his result. A dishonest shopkeeper professes to sell pulses at the cost price, but he uses a false weight of J=Agm. for a kg. )is gain is IW. A software engineer has the capability of thinking <AA lines of code in five minutes and can type <AA lines of code in <A minutes. )e takes a break for five minutes after every ten minutes. )ow many lines of codes will he complete typing after an hour` A man was engaged on a ;ob for @A days on the condition that he would get a wage of $s. <A for the day he works, but he have to pay a fine of $s. - for each day of his absence. #f he gets $s. -<? at the end, he was absent for work for ... days. A contractor agreeing to finish a work in <=A days, employed F= men each working D hours daily. After JA days, only -KF of the work was completed. #ncreasing the number of men by MMMMMMMM each working now for <A hours daily, the work can be completed in time. what is a percent of b divided by b percent of a` 'a( a 'b( b 'c( < 'd( <A 'd( <AA

-. @. B.

=.

?.

F. D.

A man bought a horse and a cart. #f he sold the horse at <A W loss and the cart at -A W gain, he would not lose anythingX but if he sold the horse at =W loss and the cart at =W gain, he would lose $s. <A in the bargain. *he amount paid by him was $s.MMMMMMM for the horse and $s.MMMMMMMM for the cart.

<AB

J.

A tennis marker is trying to put together a team of four players for a tennis tournament out of seven available. males 7 a, b and cX females & m, n, o and p. All players are of e,ual ability and there must be at least two males in the team. /or a team of four, all players must be able to play with each other under the following restrictions5 b should not play with m, c should not play with p, and a should not play with o. Ehich of the following statements must be false` <. b and p cannot be selected together -. c and o cannot be selected together @. c and n cannot be selected together. <A7<-. *he following figure depicts three views of a cube. %ased on this, answer ,uestions <A7<-. ? < = -@ @ B ?

<A. <<. <-.

*he number on the face opposite to the face carrying < is MMMMMMM . *he number on the faces ad;acent to the face marked = are MMMMMMM . Ehich of the following pairs does not correctly give the numbers on the opposite faces. '<( ?,= '-( B,< '@( <,@ 'B( B,/ive farmers have F, J, <<, <@ U <B apple trees, respectively in their orchards. .ast year, each of them discovered that every tree in their own orchard bore e3actly the same number of apples. /urther, if the third farmer gives one apple to the first, and the fifth gives three to each of the second and the fourth, they would all have e3actly the same number of apples. Ehat were the yields per tree in the orchards of the third and fourth farmers` /ive boys were climbing a hill. C was following ). $ was ;ust ahead of ". _ was between " U ). *hey were climbing up in a column. Eho was the second`

<@.

<B.

<=7<D Cohn is undecided which of the four novels to buy. )e is considering a spy thriller, a urder mystery, a "othic romance and a science fiction novel. *he books are written by $othko, "orky, %urchfield and )opper, not necessary in that order, and published by )eron, 4iegon, %lue;a and sparrow, not necessary in that order.
<A=

< @ B <=. <?. <F. <D.

'<( *he book by $othko is published by Sparrow. '-( *he Spy thriller is published by )eron. '@( *he science fiction novel is by %urchfield and is not published by %lue;a. 'B(*he "othic romance is by )opper. 4igeon publishes MMMMMMMMMMMM. *he novel by "orky MMMMMMMMMMMMMMMM. Cohn purchases books by the authors whose names come first and third in alphabetical order. )e does not buy the books MMMMMM. On the basis of the first paragraph and statement '-(, '@( and 'B( only, it is possible to deduce that <. $othko wrote the murder mystery or the spy thriller -. Sparrow published the murder mystery or the spy thriller @. *he book by %urchfield is published by Sparrow. #f a light flashes every ? seconds, how many times will it flash in c of an hour` #f point 4 is on line segment A%, then which of the following is always true` '<( A4 > 4% '-( A4 Q 4% '@( 4% Q A4 'B( A% Q A4 '=( A% Q A4 9 4% All men are vertebrates. Some mammals are vertebrates. Ehich of the following conclusions drawn from the above statement is correct. All men are mammals All mammals are men Some vertebrates are mammals. !one Ehich of the following statements drawn from the given statements are correct` "iven5 All watches sold in that shop are of high standard. Some of the ) * watches are sold in that shop. a( All watches of high standard were manufactured by ) *. b( Some of the ) * watches are of high standard. c( !one of the ) * watches is of high standard. d( Some of the ) * watches of high standard are sold in that shop. <. -. @. B. =. ?. Ashland is north of 2ast .iverpool and west of Coshocton. %owling green is north of Ashland and west of /redericktown. Dover is south and east of Ashland. 2ast .iverpool is north of /redericktown and east of Dover. /redericktown is north of Dover and west of Ashland. Coshocton is south of /redericktown and west of Dover.

<J. -A. -<.

--.

-@7-F.

<A?

-@.

Ehich of the towns mentioned is furthest of the north & west 'a( Ashland 'b( %owling green 'c( Coshocton 'd( 2ast .iverpool 'e( /redericktown Ehich of the following must be both north and east of /redericktown` 'a( Ashland 'b( Coshocton 'c( 2ast .iverpool # a only ## b only ### c only #+ a U b +aUc Ehich of the following towns must be situated both south and west of at least one other town` A. Ashland only %. Ashland and /redericktown C. Dover and /redericktown D. Dover, Coshocton and /redericktown 2. Coshocton, Dover and 2ast .iverpool. Ehich of the following statements, if true, would make the information in the numbered statements more specific` 'a( Coshocton is north of Dover. 'b( 2ast .iverpool is north of Dover 'c( Ashland is east of %owling green. 'd( Coshocton is east of /redericktown 'e( %owling green is north of /redericktown Ehich of the numbered statements gives information that can be deduced from one or more of the other statements` 'A( < '%( 'C( @ 'D( B '2( ? 2ight friends )arsha, /akis, %ala;i, 2swar, Dhinesh, Chandra, "eetha, and Ahmed are sitting in a circle facing the center. %ala;i is sitting between "eetha and Dhinesh. )arsha is third to the left of %ala;i and second to the right of Ahmed. Chandra is sitting between Ahmed and "eetha and %ala;i and 2shwar are not sitting opposite to each other. Eho is third to the left of Dhinesh` #f every alternative letter starting from % of the 2nglish alphabet is written in small letter, rest all are written in capital letters, how the month [ September\ be written. '<( Sept2 b2r '-( S2p*e %2r '@( Septembe$ 'B( Septe ber '=( !one of the above. *he length of the side of a s,uare is represented by 39-. *he length of the side of an e,uilateral triangle is -3. #f the s,uare and the e,uilateral triangle have e,ual perimeter, then the value of 3 is MMMMMMM.

-B.

-=.

-?.

-F.

-D.

-J.

@A.

<AF

@<. @-. @@. @B.

#t takes r. _arthik y hours to complete typing a manuscript. After - hours, he was called away. Ehat fractional part of the assignment was left incomplete` Ehich of the following is larger than @K=` '<( d '-( @JK=A '@( FK-= 'B( @K<A '=( =JK<AA

*he number that does not have a reciprocal is MMMMMMMMMMMM. *here are @ persons Sudhir, Arvind, and "auri. Sudhir lent cars to Arvind and "auri as many as they had already. After some time Arvind gave as many cars to Sudhir and "auri as many as they have. After sometime "auri did the same thing. At the end of this transaction each one of them had -B. /ind the cars each originally had. A man bought a horse and a cart. #f he sold the horse at <A W loss and the cart at -A W gain, he would not lose anythingX but if he sold the horse at =W loss and the cart at =W gain, he would lose $s. <A in the bargain. *he amount paid by him was $s.MMMMMMM for the horse and $s.MMMMMMMM for the cart.

@=.

1ns6ers: <. Ans)er/ @A days. 01p2anati!n/ "efore: One day work One man1s one day work &ow: !o. Of workers One day work

> > > >

< K -A < K ' -A 8 F=( =A =A 8 < K ' -A 8 F=(

*he total no. of days re,uired to complete the work > 'F= 8 -A( K =A > @A -. Ans)er/ AW 01p2anati!n/ Since @3 K - > 3 K '- K @( Ans)er/ =.@ W 01p2anati!n/ )e sells J=A grams of pulses and gains =A grams. #f he sells <AA grams of pulses then he will gain '=A K J=A( 8<AA > =.-? Ans)er/ -=A lines of codes

@.

B.
<AD

=.

Ans)er/ F days 01p2anati!n/ *he e,uation portraying the given problem is5 <A 8 3 & - 8 '@A & 3( > -<? where 3 is the number of working days. Solving this we get 3 > -@ !umber of days he was absent was F '@A7-@( days. Ans)er/ <=A men. 01p2anati!n/ One day1s work One hour1s work One man1s work

?.

> > >

- K 'F 8 JA( - K 'F 8 JA 8 D( - K 'F 8 JA 8 D 8 F=(

*he remaining work '=KF( has to be completed within ?A days, because the total number of days allotted for the pro;ect is <=A days. So we get the e,uation '- 8 <A 8 3 8 ?A( K 'F 8 JA 8 D 8 F=( > =KF where 3 is the number of men working after the JAth day. Ee get 3 > --= Since we have F= men already, it is enough to add only <=A men. F. Ans)er/ 'c( < 01p2anati!n/ a percent of b 5 'aK<AA( 8 b b percent of a 5 'bK<AA( 8 a a percent of b divided by b percent of a 5 ''a K <AA (8b( K 'bK<AA( 8 a (( > < Ans)er/ Cost price of horse > $s. BAA U the cost price of cart > -AA. 01p2anati!n/.et 3 be the cost price of the horse and y be the cost price of the cart. #n the first sale there is no loss or profit. 'i.e.( *he loss obtained is e,ual to the gain. *herefore '<AK<AA( 8 3 > '-AK<AA( 8 y

D.

G > - 8 y 77777777777777777'<( #n the second sale, he lost $s. <A. 'i.e.( *he loss is greater than the profit by $s. <A.
<AJ

*herefore '= K <AA( 8 3 > '= K <AA( 8 y 9 <A 7777777'-( Substituting '<( in '-( we get '<A K <AA( 8 y > '= K <AA( 8 y 9 <A '= K <AA( 8 y > <A ( 7 200 /rom '<( - 8 -AA > x 7 .00 J. Ans)er/ @. 01p2anati!n/ Since inclusion of any male player will re;ect a female from the team. Since there should be four member in the team and only three males are available, the girl, n should included in the team always irrespective of others selection. Ans)er/ = Ans)er/ <,-,@ U B Ans)er/ % Ans)er/ << U J apples per tree. 01p2anati!n/ .et a, b, c, d U e be the total number of apples bored per year in A, %, C, D U 2 0s orchard. "iven that a 9 < > b 9 @ > c & < > d 9 @ > e & ? %ut the ,uestion is to find the number of apples bored per tree in C and D 0s orchard. #f is enough to consider c & < > d 9 @. Since the number of trees in C1s orchard is << and that of D1s orchard is <@. .et 3 and y be the number of apples bored per tree in C U d 0s orchard respectively. *herefore << 3 & < > <@ y 9 @ %y trial and error method, we get the value for 3 and y as << and J Ans)er/ ". 01p2anati!n/ *he order in which they are climbing is $ & " & _ & ) & C Ans)er/ !ovel !ame Spy thriller
<<A

<A. <<. <-. <@.

<B.

<= & <D Author $athko 4ublisher )eron

urder mystery "othic romance Science fiction 01p2anati!n/ "iven !ovel !ame Spy thriller urder mystery "othic romance Science fiction

"orky %urchfield )opper

4iegon %lue;a Sparrow

Author $athko "orky %urchfield )opper

4ublisher )eron 4iegon %lue;a Sparrow

Since %lue;a doesn1t publish the novel by %urchfield and )eron publishes the novel spy thriller, 4iegon publishes the novel by %urchfield. Since )opper writes "othic romance and )eron publishes the novel spy thriller, %lue;a publishes the novel by )opper. Since )eron publishes the novel spy thriller and )eron publishes the novel by "orky, "orky writes Spy thriller and $athko writes urder mystery. <J. Ans)er/ B=< times. 01p2anati!n/ *here are ?A minutes in an hour. #n c of an hour there are '?A 8 c( minutes > B= minutes. #n c of an hour there are '?A 8 B=( seconds > -FAA seconds. .ight flashed for every ? seconds. #n -FAA seconds -FAAK? > B=A times. *he count start after the first flash, the light will flashes B=< times in c of an hour. Ans)er/ 'B( 01p2anati!n/ 4 A % Since p is a point on the line segment A%, A% Q A4 -<. --. Ans)er/ 'c( Ans)er/ 'b( U 'd(.

-A.

<<<

Ahmed -@ 7 -F.Ans)er/ /akis -D. Ans)er/ /akis 01p2anati!n/ )arsha 2swar Dhinesh 289 Ans)er/ '=(. 01p2anati!n/ Since every alternative letter starting from % of the 2nglish alphabet is written in small letter, the letters written in small letter are b, d, f... #n the first two answers the letter 2 is written in both small U capital letters, so they are not the correct answers. %ut in third and fourth answers the letter is written in small letter instead capital letter, so they are not the answers9 Ans)er/ 3>B 01p2anati!n/ Since the side of the s,uare is 3 9 -, its perimeter > B '3 9 -( > B3 9 D Since the side of the e,uilateral triangle is -3, its perimeter > @ 8 -3 > ?3 Also, the perimeters of both are e,ual. 'i.e.( B3 9 D > ?3 'i.e.( -3 > D 3 > B. Ans)er/ = 'y & -( K y. 01p2anati!n/ *o type a manuscript karthik took y hours. *herefore his speed in typing > <Ky. )e was called away after - hours of typing. *herefore the work completed > <Ky 8 -. *herefore the remaining work to be completed > < & -Ky. 'i.e.( work to be completed > 'y7-(Ky Ans)er/ '-( Ans)er/ < 01p2anati!n/ %ala;i Chandra =eetha

:09

@<.

@-. @@.

<<-

One is the only number e3ists without reciprocal because the reciprocal of one is one itself. @B. Ans)er/ Sudhir had @J cars, Arvind had -< cars and "auri had <- cars. 01p2anati!n/ Sudhir Arvind /inally -B %efore "auri1s transaction <%efore Arvind1s transaction ? %efore Sudhir1 s transaction @J @=. -B <B-<

"auri -B BD -B <-

Ans)er/ Cost price of horse5 $s. BAA U Cost price of cart5 $s. -AA 01p2anati!n/ .et 3 be the cost of horse U y be the cost of the cart. <A W of loss in selling horse > -A W of gain in selling the cart *herefore '<A K <AA( 8 3 > '-A 8 <AA( 8 y 3 > -y 77777777777'<( = W of loss in selling the horse is <A more than the = W gain in selling the cart. *herefore '= K <AA( 8 3 7 <A > '= K <AA( 8 y =3 7 <AAA > =y Substituting '<( <Ay 7 <AAA > =y =y > <AAA y > -AA 3 > BAA from '<(

01ercise 2.1 ;or the follo6in5) fin& the next term in the series <. ?, -B, ?A,<-A, -<A a( @@? b( @?? c( @@A d( ??A ' T.T means product(

Ans)er 5 a( @@? 01p2anati!n 5 *he series is <.-.@, -.@.B, @.B.=, B.=.?, =.?.F, ..... -. <, =, <@, -= Ans)er 5 B< 01p2anati!n 5 *he series is of the form A6-9<6-, <6-9-6-,...
<<@

@. A, =, D, <F Ans)er 5 -B 01p2anati!n 5 <6-7<, -6-9<, @6-7<, B6-9<, =6-7< B. <, D, J, ?B, -= ')int 5 2very successive terms are related(

Ans)er 5 -<? 01p2anati!n 5 <6-, -6@, @6-, B6@, =6-, ?6@ =. D,-B,<-,@?,<D,=B Ans)er 5 -F ?. F<,F?,?J,FB,?F,FAns)er 5 ?F F. =,J,<?,-J,=B Ans)er 5 <A@ 01p2anati!n 5 =8-7<>JX J8-7-><?X <?8-7@>-JX -J8-7B>=BX =B8-7=><A@ D. <,-,B,<A,<?,BA,?B 'Successive terms are related( Ans)er 5 -AA 01p2anati!n 5 *he series is powers of - '-6A,-6<,..(. All digits are less than D. 2very second number is in octal number system. <-D should follow ?B. <-D base <A > -AA base D. 01ercise 2.2 ;in& the o&& m'n out9 <. @,=,F,<-,<@,<F,<J Ans)er 5 <01p2anati!n 5 All but <- are odd numbers -. -,=,<A,<F,-?,@F,=A,?B Ans)er 5 ?B 01p2anati!n 5 -9@>=X =9=><AX <A9F><FX <F9J>-?X -?9<<>@FX @F9<@>=AX =A9<=>?=X @. <A=,D=,?A,@A,A,7B=,7JA Ans)er 5 A 01p2anati!n 5 <A=7-A>D=X D=7-=>?AX ?A7@A>@AX @A7@=>7=X 7=7BA>7B=X 7B=7B=>7JAX 01ercise % <ol=e the follo6in59
<<B

<. Ehat is the number of zeros at the end of the product of the numbers from < to <AA` Ans)er 5 <-F -. A fast typist can type some matter in - hours and a slow typist can type the same in @ hours. #f both type combinely, in how much time will they finish` Ans)er 5 < hr <- min 01p2anati!n / *he fast typistTs work done in < hr > <K*he slow typistTs work done in < hr > <K@ #f they work combinely, work done in < hr > <K-9<K@ > =K? So, the work will be completed in ?K= hours. i.e., <9<K= hours > <hr <- min @. "avaskarTs average in his first =A innings was =A. After the =<st innings, his average was =<. )ow many runs did he score in his =<st innings. 'supposing that he lost his wicket in his =<st innings( Ans)er 5 <A< 01p2anati!n 5 *otal score after =A innings > =A8=A > -=AA *otal score after =< innings > =<8=< > -?A< So, runs made in the =<st innings > -?A<7-=AA > <A< #f he had not lost his wicket in his =<st innings, he would have scored an unbeaten =A in his =<st innings. B. Out of DA coins, one is counterfeit. Ehat is the minimum number of weighings needed to find out the counterfeit coin` Ans)er 5 B =. Ehat can you conclude from the statement 5 All green are blue, all blue are red. ` 'i( some blue are green 'ii( some red are green 'iii( some green are not red 'iv( all red are blue 'a( i or ii but not both 'b( i U ii only 'c( iii or iv but not both 'd( iii U iv Ans)er 5 'b( ?. A rectangular plate with length D inches, breadth << inches and thickness - inches is available. Ehat is the length of the circular rod with diameter D inches and e,ual to the volume of the rectangular plate` Ans)er 5 @.= inches 01p2anati!n 5 +olume of the circular rod 'cylinder( > +olume of the rectangular plate '--KF(8B8B8h > D8<<8h > FK- > @.=
<<=

F. Ehat is the sum of all numbers between <AA and <AAA which are divisible by <B ` Ans)er 5 @=@J01p2anati!n 5 *he number closest to <AA which is greater than <AA and divisible by <B is <<-, which is the first term of the series which has to be summed. *he number closest to <AAA which is less than <AAA and divisible by <B is JJB, which is the last term of the series. <<- 9 <-? 9 .... 9 JJB > <B'D9J9 ... 9 F<( > @=@JD. #f s'a( denotes s,uare root of a, find the value of s'<-9s'<-9s'<-9 ...... upto infinity. Ans)er 5 B 01p2anati!n 5 .et 3 > s'<-9s'<-9s'<-9..... Ee can write 3 > s'<-93(. i.e., 36- > <- 9 3. Solving this ,uadratic e,uation, we get 3 > 7@ or 3>B. Sum cannot be 7ve and hence sum > B. J. A cylindrical container has a radius of eight inches with a height of three inches. Compute how many inches should be added to either the radius or height to give the same increase in volume` Ans)er 5 <?K@ inches 01p2anati!n 5 .et 3 be the amount of increase. *he volume will increase by the same amount if the radius increased or the height is increased. So, the effect on increasing height is e,ual to the effect on increasing the radius. i.e., '--KF(8D8D8'@93( > '--KF(8'D93(8'D93(8@ Solving the ,uadratic e,uation we get the 3 > A or <?K@. *he possible increase would be by <?K@ inches. <A. Eith ;ust si3 weights and a balance scale, you can weigh any unit number of kgs from < to @?B. Ehat could be the si3 weights` Ans)er 5 <, @, J, -F, D<, -B@ 'All powers of @( <<. Diophantus passed one si3th of his life in childhood, one twelfth in youth, and one seventh more as a bachelorX five years after his marriage a son was born who died four years before his father at half his final age. )ow old is Diophantus` Ans)er 5 DB years 01p2anati!n 5 3K? 9 3K<- 9 3KF 9 = 9 3K- 9 B > 3 <- . #f time at this moment is J 4. ., what will be the time -@JJJJJJJJ- hours later` Ans)er 5 < 4. . 01p2anati!n 5 -B billion hours later, it would be J 4. . and D hours before that it would be < 4. . <@. )ow big will an angle of one and a half degree look through a glass that magnifies things three times` Ans)er 5 < <K- degrees 01p2anati!n 5 *he magnifying glass cannot increase the magnitude of an angle.

<<?

<B. Divide B= into four parts such that when - is added to the first part, - is subtracted from the second part, - is multiplied by the third part and the fourth part is divided by two, all result in the same number. Ans)er5 D, <-, =, -A 01p2anati!n5 a 9 b 9 c 9 d >B=X a9- > b7- > -c > dK-X a>b7BX c > 'b7-(K-X d > -'b7-(X b7B 9 b 9 'b7-(K- 9 -'b7-( > B=X <=. # drove ?A km at @A kmph and then an additional ?A km at =A kmph. Compute my average speed over my <-A km. Ans)er 5 @F <K01p2anati!n 5 *ime re,d for the first ?A km > <-A min.X *ime re,d for the second ?A km > F- min.X *otal time re,d > <J- min Avg speed > '?A8<-A(K<J- > @F <KAuestions 10 and 15 are .ased on the following : /ive e3ecutives of 2uropean Corporation hold a Conference in $ome r. A converses in Spanish U #talian r. %, a spaniard, knows 2nglish also r. C knows 2nglish and belongs to #taly r. D converses in /rench and Spanish r. 2 , a native of #taly knows /rench <?. Ehich of the following can act as interpreter if r. C U r. D wish to converse a( only r. A b( Only r. % c( r. A U r. % d( Any of the other three Ans)er 5 d( Any of the other three. 01p2anati!n 5 /rom the data given, we can infer the following. A knows Spanish, #talian % knows Spanish, 2nglish C knows #talian, 2nglish D knows Spanish, /rench 2 knows #talian, /rench *o act as an interpreter between C and D, a person has to know one of the combinations #talianUSpanish, #talianU/rench, 2nglishUSpanish, 2nglishU/rench A, %, and 2 know atleast one of the combinations. <F. #f a ?th e3ecutive is brought in, to be understood by ma3imum number of original five he should be fluent in a( 2nglish U /rench b( #talian U Spanish c( 2nglish U /rench d( /rench U #talian Ans)er 5 b( #talian U Spanish 01p2anati!n 5 !o of e3ecutives who know i( 2nglish is ii( Spanish is @ iii( #talian is @
<<F

iv( /rench is #talian U Spanish are spoken by the ma3imum no of e3ecutives. So, if the ?th e3ecutive is fluent in #talian U Spanish, he can communicate with all the original five because everybody knows either Spanish or #talian. <D. Ehat is the sum of the first -= natural odd numbers` Ans)er 5 ?-= 01p2anati!n 5 *he sum of the first n natural odd nos is s,uare'n(. <9@ > B > s,uare'-( <9@9= > J > s,uare'@( <J. *he sum of any seven consecutive numbers is divisible by a( - b( F c( @ d( << 01ercise % Tr( the follo6in59 <. *here are seventy clerks working in a company, of which @A are females. Also, @A clerks are marriedX -B clerks are above -= years of ageX <J married clerks are above -= years, of which F are malesX <- males are above -= years of ageX and <= males are married. )ow many bachelor girls are there and how many of these are above -=` -. A man sailed off from the !orth 4ole. After covering -,AAA miles in one direction he turned Eest, sailed -,AAA miles, turned !orth and sailed ahead another -,AAA miles till he met his friend. )ow far was he from the !orth 4ole and in what direction` @. )ere is a series of comments on the ages of three persons C, $, S by themselves. S 5 *he difference between $Ts age and mine is three years. C 5 $ is the youngest. $ 5 2ither # am -B years old or C -= or S -?. C 5 All are above -B years of age. S 5 # am the eldest if and only if $ is not the youngest. $ 5 S is elder to me. C 5 # am the eldest. $ 5 S is not -F years old. S 5 *he sum of my age and CTs is two more than twice $Ts age. One of the three had been telling a lie throughout whereas others had spoken the truth. Determine the ages of S,C,$. B. #n a group of five people, what is the probability of finding two persons with the same month of birth` =. A father and his son go out for a Twalk7and7runT every morning around a track formed by an e,uilateral triangle. *he fatherTs walking speed is - mph and his
<<D

running speed is = mph. *he sonTs walking and running speeds are twice that of his father. %oth start together from one ape3 of the triangle, the son going clockwise and the father anti7clockwise. #nitially the father runs and the son walks for a certain period of time. *hereafter, as soon as the father starts walking, the son starts running. %oth complete the course in B= minutes. /or how long does the father run` Ehere do the two cross each other` ?. *he Director of edical Services was on his annual visit to the 2!* )ospital. Ehile going through the out patientsT records he came across the following data for a particular day 5 N 2ar consultations B=X !ose =AX *hroat FAX 2ar and !ose @AX !ose and *hroat -AX 2ar and *hroat @AX 2ar, !ose and *hroat <AX *otal patients <AA.N *hen he came to the conclusion that the records were bogus. Eas he right` F. Amongst $am, Sham and "obind are a doctor, a lawyer and a police officer. *hey are married to $adha, "ita and Sita 'not in order(. 2ach of the wives have a profession. "obindTs wife is an artist. $am is not married to "ita. *he lawyerTs wife is a teacher. $adha is married to the police officer. Sita is an e3pert cook. EhoTs who` D. Ehat should come ne3t` <, -, B, <A, <?, BA, ?B, Auestions ?312 are .ased on the following : *hree adults & $oberto, Sarah and +icky & will be traveling in a van with five children & /reddy, )illary, Conathan, .upe, and arta. *he van has a driver1s seat and one passenger seat in the front, and two benches behind the front seats, one beach behind the other. 2ach bench has room for e3actly three people. 2veryone must sit in a seat or on a bench, and seating is sub;ect to the following restrictions5 An adult must sit on each bench. 2ither $oberto or Sarah must sit in the driver1s seat. Conathan must sit immediately beside arta. J. Of the following, who can sit in the front passenger seat ` 'a( Conathan 'b( .upe 'c( $oberto 'd( Sarah 'e( +icky <A. Ehich of the following groups of three can sit together on a bench` 'a( /reddy, Conathan and arta 'b( /reddy, Conathan and +icky 'c( /reddy, Sarah and +icky 'd( )illary, .upe and Sarah 'e( .upe, arta and $oberto <<. #f /reddy sits immediately beside +icky, which of the following cannot be true ` a. Conathan sits immediately beside Sarah b. .upe sits immediately beside +icky c. )illary sits in the front passenger seat d. /reddy sits on the same bench as )illary
<<J

e. )illary sits on the same bench as $oberto <-. #f Sarah sits on a bench that is behind where Conathan is sitting, which of the following must be true ` a. )illary sits in a seat or on a bench that is in front of where arta is sitting b. .upe sits in a seat or on a bench that is in front of where /reddy is sitting c. /reddy sits on the same bench as )illary d. .upe sits on the same bench as Sarah e. arta sits on the same bench as +icky <@. ake si3 s,uares of the same size using twelve match7sticks. ')int 5 Hou will need an adhesive to arrange the re,uired figure(

<B. A farmer has two rectangular fields. *he larger field has twice the length and B times the width of the smaller field. #f the smaller field has area _, then the area of the larger field is greater than the area of the smaller field by what amount` 'a( ?_ 'b( D_ 'c( <-_ 'd( F_ <=. !ine e,ual circles are enclosed in a s,uare whose area is @?s, units. /ind the area of each circle. <?. *here are J cards. Arrange them in a @8@ matri3. Cards are of B colors. *hey are red, yellow, blue, green. Conditions for arrangement5 one red card must be in first row or second row. - green cards should be in @ rd column. Hellow cards must be in the @ corners only. *wo blue cards must be in the -nd row. At least one green card in each row. <F. #s z less than w` z and w are real numbers. '#( z- > -= '##( w > J *o answer the ,uestion, a( 2ither # or ## is sufficient b( %oth # and ## are sufficient but neither of them is alone sufficient c( # U ## are sufficient d( %oth are not sufficient <D. A speaks truth FAW of the timeX % speaks truth DAW of the time. Ehat is the probability that both are contradicting each other` <J. #n a family F children donTt eat spinach, ? donTt eat carrot, = donTt eat beans, B donTt eat spinach U carrots, @ donTt eat carrot U beans, - donTt eat beans U spinach. One doesnTt eat all @. /ind the no. of children. -A. Anna, %ena, Catherina and Diana are at their monthly business meeting. *heir occupations are author, biologist, chemist and doctor, but not necessarily in that order. Diana ;ust told the neighbour, who is a biologist that Catherina was on her
<-A

way with doughnuts. Anna is sitting across from the doctor and ne3t to the chemist. *he doctor was thinking that %ena was a good name for parentTs to choose, but didnTt say anything. Ehat is each personTs occupation`

<-<

UNIX Concepts
:!#G Concepts
S2C*#O! 7 # /#.2 A!A"2 2!* #! :!#G 1. )ow are devices represented in Q&+Z? All devices are represented by files called special files that are located inKdev directory. *hus, device files and other files are named and accessed in the same way. A Tregular fileT is ;ust an ordinary data file in the disk. A Tblock special fileT represents a device with characteristics similar to a disk 'data transfer in terms of blocks(. A Tcharacter special fileT represents a device with characteristics similar to a keyboard 'data transfer is by stream of bits in se,uential order(. 2. What is WinodeW? All :!#G files have its description stored in a structure called TinodeT. *he inode contains info about the file7size, its location, time of last access, time of last modification, permission and so on. Directories are also represented as files and have an associated inode. #n addition to descriptions about the file, the inode contains pointers to the data blocks of the file. #f the file is large, inode has indirect pointer to a block of pointers to additional data blocks 'this further aggregates for larger files(. A block is typically Dk. #node consists of the following fields5 /ile owner identifier /ile type /ile access permissions /ile access times !umber of links /ile size .ocation of the file data 3. "rief a.out the directory representation in Q&+Z A :ni3 directory is a file containing a correspondence between filenames and inodes. A directory is a special file that the kernel maintains. Only kernel modifies directories, but processes can read directories. *he contents of a directory are a list of filename and inode number pairs. Ehen new directories are created, kernel makes two entries named T.T 'refers to the directory itself( and T..T 'refers to parent directory(. System call for creating directory is mkdir 'pathname, mode(. *. What are the Qnix system calls for +GE?
<--

open'pathname,flag,mode( 7 open file creat'pathname,mode( 7 create file close'filedes( 7 close an open file read'filedes,buffer,bytes( 7 read data from an open file write'filedes,buffer,bytes( 7 write data to an open file lseek'filedes,offset,from( 7 position an open file dup'filedes( 7 duplicate an e3isting file descriptor dup-'oldfd,newfd( 7 duplicate to a desired file descriptor fcntl'filedes,cmd,arg( 7 change properties of an open file ioctl'filedes,re,uest,arg( 7 change the behaviour of an open file *he difference between fcntl anf ioctl is that the former is intended for any open file, while the latter is for device7specific operations. -. )ow do you change <ile 6ccess >ermissions? 2very file has following attributes5 ownerTs user #D ' <? bit integer ( ownerTs group #D ' <? bit integer ( /ile access mode word Tr w 3 7r w 37 r w 3T 'user permission7group permission7others permission( r7read, w7write, 37e3ecute *o change the access mode, we use chmod'filename,mode(. 23ample <5 *o change mode of myfile to Trw7rw7r77T 'ie. read, write permission for user 7 read,write permission for group 7 only read permission for others( we give the args as5 chmod'myfile,A??B( . 2ach operation is represented by discrete values TrT is B TwT is T3T is < *herefore, for TrwT the value is ?'B9-(. 23ample -5 *o change mode of myfile to Trw3r77r77T we give the args as5 chmod'myfile,AFBB(. 0. What are lin's and sym.olic lin's in Q&+Z file system? A link is a second name 'not a file( for a file. .inks can be used to assign more than one name to a file, but cannot be used to assign a directory more than one name or link filenames on different computers. Symbolic link TisT a file that only contains the name of another file.Operation on the symbolic link is directed to the file pointed by the it.%oth the limitations of links are eliminated in symbolic links. Commands for linking files are5 .ink ln filename< filenameSymbolic link ln 7s filename< filename<-@

5. What is a <+<E? /#/O are otherwise called as Tnamed pipesT. /#/O 'first7in7first7out( is a special file which is said to be data transient. Once data is read from named pipe, it cannot be read again. Also, data can be read only in the order written. #t is used in interprocess communication where a process writes to one end of the pipe 'producer( and the other reads from the other end 'consumer(. 7. )ow do you create special files li'e named pipes and device files? *he system call mknod creates special files in the following se,uence. <. kernel assigns new inode, -. sets the file type to indicate that the file is a pipe, directory or special file, @. #f it is a device file, it makes the other entries like ma;or, minor device numbers. /or e3ample5 #f the device is a disk, ma;or device number refers to the disk controller and minor device number is the disk. ?. !iscuss the mount and unmount system calls *he privileged mount system call is used to attach a file system to a directory of another file systemX the unmount system call detaches a file system. Ehen you mount another file system on to your directory, you are essentially splicing one directory tree onto a branch in another directory tree. *he first argument to mount call is the mount point, that is , a directory in the current file naming system. *he second argument is the file system to mount to that point. Ehen you insert a cdrom to your uni3 systemTs drive, the file system in the cdrom automatically mounts to KdevKcdrom in your system. 1@. )ow does the inode map to data .loc' of a file? #node has <@ block addresses. *he first <A are direct block addresses of the first <A data blocks in the file. *he <<th address points to a one7level inde3 block. *he <-th address points to a two7level 'double in7direction( inde3 block. *he <@th address points to a three7level'triple in7direction(inde3 block. *his provides a very large ma3imum file size with efficient access to large files, but also small files are accessed directly in one disk read. 11. What is a shell? A shell is an interactive user interface to an operating system services that allows an user to enter commands as character strings or through a graphical user interface. *he shell converts them to system calls to the OS or forks off a process to e3ecute the command. System call results and other information from the OS are presented to the user through an interactive interface. Commonly used shells are sh,csh,ks etc. S2C*#O! 7 ## 4$OC2SS OD2. and #4C

1. "rief a.out the initial process se/uence while the system .oots up. Ehile booting, special process called the TswapperT or TschedulerT is created with
<-B

4rocess7#D A. *he swapper manages memory allocation for processes and influences C4: allocation. *he swapper inturn creates @ children5 the process dispatcher, vhand and dbflush with #Ds <,- and @ respectively. *his is done by e3ecuting the file KetcKinit. 4rocess dispatcher gives birth to the shell. :ni3 keeps track of all the processes in an internal data structure called the 4rocess *able 'listing command is ps 7el(. 2. What are various +!s associated with a process? :ni3 identifies each process with a uni,ue integer called 4rocess#D. *he process that e3ecutes the re,uest for creation of a process is called the Tparent processT whose 4#D is T4arent 4rocess #DT. 2very process is associated with a particular user called the TownerT who has privileges over the process. *he identification for the user is T:ser#DT. Owner is the user who e3ecutes the process. 4rocess also has T2ffective :ser #DT which determines the access privileges for accessing resources like files. getpid'( 7process id getppid'( 7parent process id getuid'( 7user id geteuid'( 7effective user id 3. 1xplain for'24 system call. *he efork'(T used to create a new process from an e3isting process. *he new process is called the child process, and the e3isting process is called the parent. Ee can tell which is which by checking the return value from efork'(T. *he parent gets the childTs pid returned to him, but the child gets A returned to him. *. >redict the output of the following program code main'( ] fork'(X printf'N)ello EorldSN(X ^ Ans)er/ )ello EorldS)ello EorldS 01p2anati!n5 *he fork creates a child that is a duplicate of the parent process. *he child begins from the fork'(.All the statements after the call to fork'( will be e3ecuted twice.'once by the parent process and other by child(. *he statement before fork'( is e3ecuted only by the parent process. -. >redict the output of the following program code main'( ] fork'(X fork'(X fork'(X
<-=

printf'N)ello EorldSN(X ^ Ans)er/ N)ello EorldN will be printed D times. 01p2anati!n5 -6n times where n is the number of calls to fork'( 0. List the system calls used for process management: <(stem +'lls 2es+ription fork'( *o create a new process e3ec'( *o e3ecute a new program in a process wait'( *o wait until a created process completes its e3ecution e3it'( *o e3it from a process e3ecution getpid'( *o get a process identifier of the current process getppid'( *o get parent process identifier nice'( *o bias the e3isting priority of a process brk'( *o increaseKdecrease the data segment size of a process 5. )ow can you getGset an environment varia.le from a program? "etting the value of an environment variable is done by using egetenv'(T. Setting the value of an environment variable is done by using eputenv'(T. 7. )ow can a parent and child process communicate? A parent and child can communicate through any of the normal inter7process communication schemes 'pipes, sockets, message ,ueues, shared memory(, but also have some special ways to communicate that take advantage of their relationship as a parent and child. One of the most obvious is that the parent can get the e3it status of the child. ?. What is a Com.ie? Ehen a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it 7 for e3ample, the parent may need to check the childTs e3it status. *o be able to get this information, the parent calls ewait'(TX #n the interval between the child terminating and the parent calling ewait'(T, the child is said to be a ezombieT '#f you do epsT, the child will have a efT in its status field to indicate this.( 1@. What are the process states in Qnix? As a process e3ecutes it changes state according to its circumstances. :ni3 processes have the following states5 $unning 5 *he process is either running or it is ready to run . Eaiting 5 *he process is waiting for an event or for a resource. Stopped 5 *he process has been stopped, usually by receiving a signal. fombie 5 *he process is dead but have not been removed from the process table. 11. What )appens when you execute a program? Ehen you e3ecute a program on your :!#G system, the system creates a special
<-?

environment for that program. *his environment contains everything needed for the system to run the program as if no other program were running on the system. 2ach process has process conte3t, which is everything that is uni,ue about the state of the program you are currently running. 2very time you e3ecute a program the :!#G system does a fork, which performs a series of operations to create a process conte3t and then e3ecute your program in that conte3t. *he steps include the following5 Allocate a slot in the process table, a list of currently running programs kept by :!#G. Assign a uni,ue process identifier '4#D( to the process. iCopy the conte3t of the parent, the process that re,uested the spawning of the new process. $eturn the new 4#D to the parent process. *his enables the parent process to e3amine or control the process directly. After the fork is complete, :!#G runs your program. 12. What )appens when you execute a command? Ehen you enter TlsT command to look at the contents of your current working directory, :!#G does a series of things to create an environment for ls and the run it5 *he shell has :!#G perform a fork. *his creates a new process that the shell will use to run the ls program. *he shell has :!#G perform an e3ec of the ls program. *his replaces the shell program and data with the program and data for ls and then starts running that new program. *he ls program is loaded into the new process conte3t, replacing the te3t and data of the shell. *he ls program performs its task, listing the contents of the current directory. 13. What is a !aemon? A daemon is a process that detaches itself from the terminal and runs, disconnected, in the background, waiting for re,uests and responding to them. #t can also be defined as the background process that does not belong to a terminal session. any system functions are commonly performed by daemons, including the sendmail daemon, which handles mail, and the !!*4 daemon, which handles :S2!2* news. any other daemons may e3ist. Some of the most common daemons are5 init5 *akes over the basic running of the system when the kernel has finished the boot process. inetd5 $esponsible for starting network services that do not have their own stand7 alone daemons. /or e3ample, inetd usually takes care of incoming rlogin, telnet, and ftp connections. cron5 $esponsible for running repetitive tasks on a regular schedule. 1*. What is WpsW command for? *he ps command prints the process status for some or all of the running processes. *he information given are the process identification number '4#D(,the amount of time that the process has taken to e3ecute so far etc. 1-. )ow would you 'ill a process? *he kill command takes the 4#D as one argumentX this identifies which process to
<-F

terminate. *he 4#D of a process can be got using TpsT command. 10. What is an advantage of executing a process in .ac'ground? *he most common reason to put a process in the background is to allow you to do something else interactively without waiting for the process to complete. At the end of the command you add the special background symbol, U. *his symbol tells your shell to e3ecute the given command in the background. 23ample5 cp 8.8 ..KbackupU 'cp is for copy( 15. )ow do you execute one program from within another? *he system calls used for low7level process creation are e3eclp'( and e3ecvp'(. *he e3eclp call overlays the e3isting program with the new one , runs that and e3its. *he original program gets back control only when an error occurs. e3eclp'path,fileMname,arguments..(X KKlast argument must be !:.. A variant of e3eclp called e3ecvp is used when the number of arguments is not known in advance. e3ecvp'path,argumentMarray(X KKargument array should be terminated by !:.. 17. What is +>,? What are the various schemes availa.le? *he term #4C '#nter74rocess Communication( describes various ways by which different process running on some operating system communicate between each other. +arious schemes available are as follows5 >ipes: One7way communication scheme through which different process can communicate. *he problem is that the two processes should have a common ancestor 'parent7child relationship(. )owever this problem was fi3ed with the introduction of named7pipes '/#/O(. #essage Aueues : essage ,ueues can be used between related and unrelated processes running on a machine. $hared #emory: *his is the fastest of all #4C schemes. *he memory to be shared is mapped into the address space of the processes 'that are sharing(. *he speed achieved is attributed to the fact that there is no kernel involvement. %ut this scheme needs synchronization. +arious forms of synchronisation are mute3es, condition7variables, read7write locks, record7locks, and semaphores. S2C*#O! 7 ### 2 O$H A!A"2 2!*

1. What is the difference .etween $wapping and >aging? $wapping:


<-D

Ehole process is moved from the swap device to the main memory for e3ecution. 4rocess size must be less than or e,ual to the available main memory. #t is easier to implementation and overhead to the system. Swapping systems does not handle the memory more fle3ibly as compared to the paging systems. >aging: Only the re,uired memory pages are moved to main memory from the swap device for e3ecution. 4rocess size does not matter. "ives the concept of the virtual memory. #t provides greater fle3ibility in mapping the virtual address space into the physical memory of the machine. Allows more number of processes to fit in the main memory simultaneously. Allows the greater process size than the available physical memory. Demand paging systems handle the memory more fle3ibly. 2. What is major difference .etween the )istoric Qnix and the new "$! release of Qnix $ystem B in terms of #emory #anagement? )istoric :ni3 uses Swapping & entire process is transferred to the main memory from the swap device, whereas the :ni3 System + uses Demand 4aging & only the part of the process is moved to the main memory. )istoric :ni3 uses one Swap Device and :ni3 System + allow multiple Swap Devices. 3. What is the main goal of the #emory #anagement? #t decides which process should reside in the main memory, anages the parts of the virtual address space of a process which is non7core resident, onitors the available main memory and periodically write the processes into the swap device to provide more processes fit in the main memory simultaneously. *. What is a #ap? A ap is an Array, which contains the addresses of the free space in the swap device that are allocatable resources, and the number of the resource units available there. Address < :nits <A,AAA

*his allows /irst7/it allocation of contiguous blocks of a resource. #nitially the ap contains one entry & address 'block offset from the starting of the swap area( and the total number of resources. _ernel treats each unit of ap as a group of disk blocks. On the allocation and freeing of the resources _ernel updates the ap for accurate information. -. What scheme does the [ernel in Qnix $ystem B follow while choosing a swap device among the multiple swap devices? _ernel follows $ound $obin scheme choosing a swap device among the multiple swap devices in :ni3 System +.
<-J

0. What is a egion? A $egion is a continuous area of a process1s address space 'such as te3t, data and stack(. *he kernel in a 0$egion *able1 that is local to the process maintains region. $egions are sharable among the process. 5. What are the events done .y the [ernel after a process is .eing swapped out from the main memory? Ehen _ernel swaps the process out of the primary memory, it performs the following5 _ernel decrements the $eference Count of each region of the process. #f the reference count becomes zero, swaps the region out of the main memory, _ernel allocates the space for the swapping process in the swap device, _ernel locks the other swapping process while the current swapping operation is going on, *he _ernel saves the swap address of the region in the region table. 7. +s the >rocess .efore and after the swap are the same? =ive reason. 4rocess before swapping is residing in the primary memory in its original form. *he regions 'te3t, data and stack( may not be occupied fully by the process, there may be few empty slots in any of the regions and while swapping _ernel do not bother about the empty slots while swapping the process out. After swapping the process resides in the swap 'secondary memory( device. *he regions swapped out will be present but only the occupied region slots but not the empty slots that were present before assigning. Ehile swapping the process once again into the main memory, the _ernel referring to the 4rocess emory ap, it assigns the main memory accordingly taking care of the empty slots in the regions. ?. What do you mean .y u3area 2user area4 or u3.loc'? *his contains the private data that is manipulated only by the _ernel. *his is local to the 4rocess, i.e. each process is allocated a u7area. 1@. What are the entities that are swapped out of the main memory while swapping the process out of the main memory? All memory space occupied by the process, process1s u7area, and _ernel stack are swapped out, theoretically. 4ractically, if the process1s u7area contains the Address *ranslation *ables for the process then _ernel implementations do not swap the u7area. 11. What is <or' swap? fork'( is a system call to create a child process. Ehen the parent process calls fork'( system call, the child process is created and if there is short of memory then the child process is sent to the read7to7run state in the swap device, and return to the user state without swapping the parent process. Ehen the memory will be available the child process will be swapped into the main memory.
<@A

12. What is 1xpansion swap? At the time when any process re,uires more memory than it is currently allocated, the _ernel performs 23pansion swap. *o do this _ernel reserves enough space in the swap device. *hen the address translation mapping is ad;usted for the new virtual address space but the physical memory is not allocated. At last _ernel swaps the process into the assigned space in the swap device. .ater when the _ernel swaps the process into the main memory this assigns memory according to the new address translation mapping. 13. )ow the $wapper wor's? *he swapper is the only process that swaps the processes. *he Swapper operates only in the _ernel mode and it does not uses System calls instead it uses internal _ernel functions for swapping. #t is the archetype of all kernel process. 1*. What are the processes that are not .othered .y the swapper? =ive eason. fombie process5 *hey do not take any up physical memory. 4rocesses locked in memories that are updating the region of the process. _ernel swaps only the sleeping processes rather than the 0ready7to7run1 processes, as they have the higher probability of being scheduled than the Sleeping processes. 1-. What are the re/uirements for a swapper to wor'? *he swapper works on the highest scheduling priority. /irstly it will look for any sleeping process, if not found then it will look for the ready7to7run process for swapping. %ut the ma;or re,uirement for the swapper to work the ready7to7run process must be core7resident for at least - seconds before swapping out. And for swapping in the process must have been resided in the swap device for at least - seconds. #f the re,uirement is not satisfied then the swapper will go into the wait state on that event and it is awaken once in a second by the _ernel. 10. What are the criteria for choosing a process for swapping into memory from the swap device? *he resident time of the processes in the swap device, the priority of the processes and the amount of time the processes had been swapped out. 15. What are the criteria for choosing a process for swapping out of the memory to the swap device? *he process1s memory resident time, 4riority of the process and *he nice value. 17. What do you mean .y nice value? !ice value is the value that controls ]increments or decrements^ the priority of the process. *his value that is returned by the nice '( system call. *he e,uation for using nice value is5 >riority I 2\recent ,>Q usage]Gconstant4 8 2.ase3 priority4 8 2nice value4
<@<

Only the administrator can supply the nice value. *he nice '( system call works for the running process only. !ice value of one process cannot affect the nice value of the other process. 1?. What are conditions on which deadloc' can occur while swapping the processes? All processes in the main memory are asleep. All 0ready7to7run1 processes are swapped out. *here is no space in the swap device for the new incoming process that are swapped out of the main memory. *here is no space in the main memory for the new incoming process. 2@. What are conditions for a machine to support !emand >aging? emory architecture must based on 4ages, *he machine must support the 0restartable1 instructions. 21. What is Xthe principle of localityF? #t1s the nature of the processes that they refer only to the small subset of the total data space of the process. i.e. the process fre,uently calls the same subroutines or e3ecutes the loop instructions. 22. What is the wor'ing set of a process? *he set of pages that are referred by the process in the last 0n1, references, where 0n1 is called the window of the working set of the process. 23. What is the window of the wor'ing set of a process? *he window of the working set of a process is the total number in which the process had referred the set of pages in the working set of the process. 2*. What is called a page fault? 4age fault is referred to the situation when the process addresses a page in the working set of the process but the process fails to locate the page in the working set. And on a page fault the kernel updates the working set by reading the page from the secondary device. 2-. What are data structures that are used for !emand >aging? _ernel contains B data structures for Demand paging. *hey are, 4age table entries, Disk block descriptors, 4age frame data table 'pfdata(, Swap7use table. 20. What are the .its that support the demand paging? +alid, $eference, odify, Copy on write, Age. *hese bits are the part of the page table entry, which includes physical address of the page and protection bits.
<@-

4age address

Age Copy on write

odify $eference

+alid 4rotection

25. )ow the [ernel handles the for'24 system call in traditional Qnix and in the $ystem B Qnix% while swapping? _ernel in traditional :ni3, makes the duplicate copy of the parent1s address space and attaches it to the child1s process, while swapping. _ernel in System + :ni3, manipulates the region tables, page table, and pfdata table entries, by incrementing the reference count of the region table of shared regions. 27. !ifference .etween the for'24 and vfor'24 system call? During the fork'( system call the _ernel makes a copy of the parent process1s address space and attaches it to the child process. %ut the vfork'( system call do not makes any copy of the parent1s address space, so it is faster than the fork'( system call. *he child process as a result of the vfork'( system call e3ecutes e3ec'( system call. *he child process from vfork'( system call e3ecutes in the parent1s address space 'this can overwrite the parent1s data and stack ( which suspends the parent process until the child process e3its. 2?. What is "$$2"loc' $tarted .y $ym.ol4? A data representation at the machine level, that has initial values when a program starts and tells about how much space the kernel allocates for the un7initialized data. _ernel initializes it to zero at run7time. 3@. What is >age3$tealer process? *his is the _ernel process that makes rooms for the incoming pages, by swapping the memory pages that are not the part of the working set of a process. 4age7Stealer is created by the _ernel at the system initialization and invokes it throughout the lifetime of the system. _ernel locks a region when a process faults on a page in the region, so that page stealer cannot steal the page, which is being faulted in. 31. &ame two paging states for a page in memory? *he two paging states are5 *he page is aging and is not yet eligible for swapping, *he page is eligible for swapping but not yet eligible for reassignment to other virtual address space. 32. What are the phases of swapping a page from the memory? 4age stealer finds the page eligible for swapping and places the page number in the list of pages to be swapped. _ernel copies the page to a swap device when necessary and clears the valid bit in the page table entry, decrements the pfdata reference count, and places the pfdata table entry at the end of the free list if its reference count is A. 33. What is page fault? +ts types?
<@@

4age fault refers to the situation of not having a page in the main memory when any process references it. *here are two types of page fault 5 +alidity fault, 4rotection fault. 3*. +n what way the <ault )andlers and the +nterrupt handlers are different? /ault handlers are also an interrupt handler with an e3ception that the interrupt handlers cannot sleep. /ault handlers sleep in the conte3t of the process that caused the memory fault. *he fault refers to the running process and no arbitrary processes are put to sleep. 3-. What is validity fault? #f a process referring a page in the main memory whose valid bit is not set, it results in validity fault. *he valid bit is not set for those pages5 that are outside the virtual address space of a process, that are the part of the virtual address space of the process but no physical address is assigned to it. 30. What does the swapping system do if it identifies the illegal page for swapping? #f the disk block descriptor does not contain any record of the faulted page, then this causes the attempted memory reference is invalid and the kernel sends a \$egmentation violation] signal to the offending process. *his happens when the swapping system identifies any invalid memory reference. 35. What are states that the page can .e in% after causing a page fault? On a swap device and not in memory, On the free page list in the main memory, #n an e3ecutable file, arked [demand zero\, arked [demand fill\. 37. +n what way the validity fault handler concludes? #t sets the valid bit of the page by clearing the modify bit. #t recalculates the process priority. 3?. 6t what mode the fault handler executes? At the _ernel ode. *@. What do you mean .y the protection fault? 4rotection fault refers to the process accessing the pages, which do not have the access permission. A process also incur the protection fault when it attempts to write a page whose copy on write bit was set during the fork'( system call. *1. )ow the [ernel handles the copy on write .it of a page% when the .it is set?
<@B

#n situations like, where the copy on write bit of a page is set and that page is shared by more than one process, the _ernel allocates new page and copies the content to the new page and the other processes retain their references to the old page. After copying the _ernel updates the page table entry with the new page number. *hen _ernel decrements the reference count of the old pfdata table entry. #n cases like, where the copy on write bit is set and no processes are sharing the page, the _ernel allows the physical page to be reused by the processes. %y doing so, it clears the copy on write bit and disassociates the page from its disk copy 'if one e3ists(, because other process may share the disk copy. *hen it removes the pfdata table entry from the page7,ueue as the new copy of the virtual page is not on the swap device. #t decrements the swap7use count for the page and if count drops to A, frees the swap space. *2. <or which 'ind of fault the page is chec'ed first? *he page is first checked for the validity fault, as soon as it is found that the page is invalid 'valid bit is clear(, the validity fault handler returns immediately, and the process incur the validity page fault. _ernel handles the validity fault and the process will incur the protection fault if any one is present. *3. +n what way the protection fault handler concludes? After finishing the e3ecution of the fault handler, it sets the modify and protection bits and clears the copy on write bit. #t recalculates the process7priority and checks for signals. **. )ow the [ernel handles .oth the page stealer and the fault handler? *he page stealer and the fault handler thrash because of the shortage of the memory. #f the sum of the working sets of all processes is greater that the physical memory then the fault handler will usually sleep because it cannot allocate pages for a process. *his results in the reduction of the system throughput because _ernel spends too much time in overhead, rearranging the memory in the frantic pace.

<@=

RDBMS Concepts
$D% S Concepts
1. What is data.ase? A database is a logically coherent collection of data with some inherent meaning, representing some aspect of real world and which is designed, built and populated with data for a specific purpose. 2. What is !"#$? #t is a collection of programs that enables user to create and maintain a database. #n other words it is general7purpose software that provides the users with the processes of defining, constructing and manipulating the database for various applications. 3. What is a !ata.ase system? *he database and D% S software together is called as Database system. *. -. 6dvantages of !"#$? $edundancy is controlled. :nauthorised access is restricted. 4roviding multiple user interfaces. 2nforcing integrity constraints. 4roviding backup and recovery. !isadvantage in <ile >rocessing $ystem? Data redundancy U inconsistency. Difficult in accessing data. Data isolation. Data integrity. Concurrent access is not possible. Security 4roblems.

0. !escri.e the three levels of data a.straction? *he are three levels of abstraction5 >hysical level: *he lowest level of abstraction describes how data are stored. Logical level: *he ne3t higher level of abstraction, describes what data are stored in database and what relationship among those data. Biew level: *he highest level of abstraction describes only part of entire database. 5. !efine the Kintegrity rulesK
<@?

*here are two #ntegrity rules. 1ntity +ntegrity: States that [4rimary key cannot have !:.. value\ eferential +ntegrity: States that [/oreign _ey can be either a !:.. value or should be 4rimary _ey value of other relation. 7. What is extension and intension? 1xtension 7 #t is the number of tuples present in a table at any instance. *his is time dependent. +ntension 7 #t is a constant value that gives the name, structure of table and the constraints laid on it. ?. What is $ystem ? What are its two major su.systems? System $ was designed and developed over a period of <JFB7FJ at #% San Cose $esearch Center. #t is a prototype and its purpose was to demonstrate that it is possible to build a $elational System that can be used in a real life environment to solve real life problems, with performance at least comparable to that of e3isting system. #ts two subsystems are $esearch Storage System $elational Data System. 1@. )ow is the data structure of $ystem different from the relational structure? :nlike $elational systems in System $ Domains are not supported 2nforcement of candidate key uni,ueness is optional 2nforcement of entity integrity is optional $eferential integrity is not enforced 11. What is !ata +ndependence? Data independence means that [the application is independent of the storage structure and access strategy of data\. #n other words, *he ability to modify the schema definition in one level should not affect the schema definition in the ne3t higher level. *wo types of Data #ndependence5 4hysical Data #ndependence5 odification in physical level should not affect the logical level. .ogical Data #ndependence5 odification in logical level should affect the view level. &ED1: Logical !ata +ndependence is more difficult to achieve 12. What is a view? )ow it is related to data independence? A view may be thought of as a virtual table, that is, a table that does not really e3ist in its own right but is instead derived from one or more underlying base table. #n other words, there is no stored file that direct represents the view instead a definition of view is stored in data dictionary.
<@F

"rowth and restructuring of base tables is not reflected in views. *hus the view can insulate users from the effects of restructuring and growth in the database. )ence accounts for logical data independence. 13. What is !ata #odel? A collection of conceptual tools for describing data, data relationships data semantics and constraints. 1*. What is 13 model? *his data model is based on real world that consists of basic ob;ects called entities and of relationship among these ob;ects. 2ntities are described in a database by a set of attributes. 1-. What is E.ject Eriented model? *his model is based on collection of ob;ects. An ob;ect contains values stored in instance variables with in the ob;ect. An ob;ect also contains bodies of code that operate on the ob;ect. *hese bodies of code are called methods. Ob;ects that contain same types of values and the same methods are grouped together into classes. 10. What is an 1ntity? #t is a TthingT in the real world with an independent e3istence. 15. What is an 1ntity type? #t is a collection 'set( of entities that have same attributes. 17. What is an 1ntity set? #t is a collection of all entities of particular entity type in the database. 1?. What is an 1xtension of entity type? *he collections of entities of a particular entity type are grouped together into an entity set. 2@. What is Wea' 1ntity set? An entity set may not have sufficient attributes to form a primary key, and its primary key compromises of its partial key and primary key of its parent entity, then it is said to be Eeak 2ntity set. 21. What is an attri.ute? #t is a particular property, which describes the entity. 22. What is a elation $chema and a elation? A relation Schema denoted by $'A<, A-, I, An( is made up of the relation name $ and the list of attributes Ai that it contains. A relation is defined as a set of tuples. .et r be the relation which contains set tuples 't<, t-, t@, ..., tn(. 2ach tuple is an ordered list of n7values t>'v<,v-, ..., vn(.
<@D

23. What is degree of a elation? #t is the number of attribute of its relation schema. 2*. What is elationship? #t is an association among two or more entities. 2-. What is elationship set? *he collection 'or set( of similar relationships. 20. What is elationship type? $elationship type defines a set of associations or a relationship set among a given set of entity types. 25. What is degree of elationship type? #t is the number of entity type participating. 2-. What is !!L 2!ata !efinition Language4? A data base schema is specifies by a set of definitions e3pressed by a special language called DD.. 20. What is B!L 2Biew !efinition Language4? #t specifies user views and their mappings to the conceptual schema. 25. What is $!L 2$torage !efinition Language4? *his language is to specify the internal schema. *his language may specify the mapping between two schemas. 27. What is !ata $torage 3 !efinition Language? *he storage structures and access methods used by database system are specified by a set of definition in a special type of DD. called data storage7definition language. 2?. What is !#L 2!ata #anipulation Language4? *his language that enable user to access or manipulate data as organised by appropriate data model. >rocedural !#L or Low level: D . re,uires a user to specify what data are needed and how to get those data. &on3>rocedural !#L or )igh level: D . re,uires a user to specify what data are needed without specifying how to get those data. 31. What is !#L ,ompiler? #t translates D . statements in a ,uery language into low7level instruction that the ,uery evaluation engine can understand. 32. What is Auery evaluation engine? #t e3ecutes low7level instruction generated by compiler.
<@J

33. What is !!L +nterpreter? #t interprets DD. statements and record them in tables containing metadata. 3*. What is ecord3at3a3time? *he .ow level or 4rocedural D . can specify and retrieve each record from a set of records. *his retrieve of a record is said to be $ecord7at7a7time. 3-. What is $et3at3a3time or $et3oriented? *he )igh level or !on7procedural D . can specify and retrieve many records in a single D . statement. *his retrieve of a record is said to be Set7at7a7time or Set7 oriented. 30. What is elational 6lge.ra? #t is procedural ,uery language. #t consists of a set of operations that take one or two relations as input and produce a new relation. 35. What is elational ,alculus? #t is an applied predicate calculus specifically tailored for relational databases proposed by 2./. Codd. 2.g. of languages based on it are DS. A.4)A, L:2.. 37. )ow does Duple3oriented relational calculus differ from domain3oriented relational calculus *he tuple7oriented calculus uses a tuple variables i.e., variable whose only permitted values are tuples of that relation. 2.g. L:2. *he domain7oriented calculus has domain variables i.e., variables that range over the underlying domains instead of over relation. 2.g. #.., D2D:C2. 3?. What is normaliCation? #t is a process of analysing the given relation schemas based on their /unctional Dependencies '/Ds( and primary key to achieve the properties inimizing redundancy inimizing insertion, deletion and update anomalies. *@. What is <unctional !ependency? A /unctional dependency is denoted by G H between two sets of attributes G and H that are subsets of $ specifies a constraint on the possible tuple that can form a relation state r of $. *he constraint is for any two tuples t< and t- in r if t<OGP > t-OGP then they have t<OHP > t-OHP. *his means the value of G component of a tuple uni,uely determines the value of component H. *1. When is a functional dependency < said to .e minimal? 2very dependency in / has a single attribute for its right hand side. Ee cannot replace any dependency G A in / with a dependency H A where H is a proper subset of G and still have a set of dependency that is e,uivalent to /. Ee cannot remove any dependency from / and still have set of dependency that is e,uivalent to /.
<BA

*2. What is #ultivalued dependency? ultivalued dependency denoted by G H specified on relation schema $, where G and H are both subsets of $, specifies the following constraint on any relation r of $5 if two tuples t< and t- e3ist in r such that t<OGP > t-OGP then t@ and tB should also e3ist in r with the following properties t@O3P > tBOGP > t<OGP > t-OGP t@OHP > t<OHP and tBOHP > t-OHP t@OfP > t-OfP and tBOfP > t<OfP where Of > '$7'G : H(( P *3. What is Lossless join property? #t guarantees that the spurious tuple generation does not occur with respect to relation schemas after decomposition. **. What is 1 &< 2&ormal <orm4? *he domain of attribute must include only atomic 'simple, indivisible( values. *-. What is <ully <unctional dependency? #t is based on concept of full functional dependency. A functional dependency G H is full functional dependency if removal of any attribute A from G means that the dependency does not hold any more. *0. What is 2&<? A relation schema $ is in -!/ if it is in <!/ and every non7prime attribute A in $ is fully functionally dependent on primary key. *5. What is 3&<? A relation schema $ is in @!/ if it is in -!/ and for every /D G A either of the following is true G is a Super7key of $. A is a prime attribute of $. #n other words, if every non prime attribute is non7transitively dependent on primary key. *7. What is ",&< 2"oyce3,odd &ormal <orm4? A relation schema $ is in %C!/ if it is in @!/ and satisfies an additional constraint that for every /D G A, G must be a candidate key. *?. What is *&<? A relation schema $ is said to be in B!/ if for every G H that holds over $, one of following is true G is subset or e,ual to 'or( GH > $. G is a super key. -@. What is -&<?
<B<

ultivalued dependency

A $elation schema $ is said to be =!/ if for every ;oin dependency ]$<, $-, ..., $n^ that holds $, one the following is true $i > $ for some i. *he ;oin dependency is implied by the set of /D, over $ in which the left side is key of $. -1. What is !omain3[ey &ormal <orm? A relation is said to be in D_!/ if all constraints and dependencies that should hold on the the constraint can be enforced by simply enforcing the domain constraint and key constraint on the relation. -2. What are partial% alternate%% artificial% compound and natural 'ey? >artial [ey: #t is a set of attributes that can uni,uely identify weak entities and that are related to same owner entity. #t is sometime called as Discriminator. 6lternate [ey: All Candidate _eys e3cluding the 4rimary _ey are known as Alternate _eys. 6rtificial [ey5 #f no obvious key, either stand alone or compound is available, then the last resort is to simply create a key, by assigning a uni,ue number to each record or occurrence. *hen this is known as developing an artificial key. ,ompound [ey/ #f no single data element uni,uely identifies occurrences within a construct, then combining multiple elements to create a uni,ue identifier for the construct is known as creating a compound key. &atural [ey/ Ehen one of the data elements stored within a construct is utilized as the primary key, then it is called the natural key. -3. What is indexing and what are the different 'inds of indexing? #nde3ing is a techni,ue for determining how ,uickly specific data can be found. *ypes5 %inary search style inde3ing %7*ree inde3ing #nverted list inde3ing emory resident table *able inde3ing -*. What is system catalog or catalog relation? )ow is .etter 'nown as? A $D% S maintains a description of all the data that it contains, information about every relation and inde3 that it contains. *his information is stored in a collection of relations maintained by the system called metadata. #t is also called data dictionary. --. What is meant .y /uery optimiCation? *he phase that identifies an efficient e3ecution plan for evaluating a ,uery that has the least estimated cost is referred to as ,uery optimization.
<B-

-0. What is join dependency and inclusion dependency? Yoin !ependency: A Coin dependency is generalization of ultivalued dependency.A CD ]$<, $-, ..., $n^ is said to hold over a relation $ if $<, $-, $@, ..., $n is a lossless7 ;oin decomposition of $ . *here is no set of sound and complete inference rules for CD. +nclusion !ependency: An #nclusion Dependency is a statement of the form that some columns of a relation are contained in other columns. A foreign key constraint is an e3ample of inclusion dependency. -5. What is dura.ility in !"#$? Once the D% S informs the user that a transaction has successfully completed, its effects should persist even if the system crashes before all its changes are reflected on disk. *his property is called durability. -7. What do you mean .y atomicity and aggregation? 6tomicity: 2ither all actions are carried out or none are. :sers should not have to worry about the effect of incomplete transactions. D% S ensures this by undoing the actions of incomplete transactions. 6ggregation: A concept which is used to model a relationship between a collection of entities and relationships. #t is used when we need to e3press a relationship among relationships. -?. What is a >hantom !eadloc'? #n distributed deadlock detection, the delay in propagating local information might cause the deadlock detection algorithms to identify deadlocks that do not really e3ist. Such situations are called phantom deadlocks and they lead to unnecessary aborts. 0@. What is a chec'point and When does it occur? A Checkpoint is like a snapshot of the D% S state. %y taking checkpoints, the D% S can reduce the amount of work to be done during restart in the event of subse,uent crashes. 01. What are the different phases of transaction? Different phases are Analysis phase $edo 4hase :ndo phase 02. What do you mean .y flat file data.ase? #t is a database in which there are no programs or user access languages. #t has no cross7file capabilities but is user7friendly and provides user7interface management.
<B@

03. What is Ktransparent !"#$K? #t is one, which keeps its 4hysical Structure hidden from user. 0*. "rief theory of &etwor'% )ierarchical schemas and their properties !etwork schema uses a graph data structure to organize records e3ample for such a database management system is C*C" while a hierarchical schema uses a tree data structure e3ample for such a system is # S. 0-. What is a /uery? A ,uery with respect to D% S relates to user commands that are used to interact with a data base. *he ,uery language can be classified into data definition language and data manipulation language. 00. What do you mean .y ,orrelated su./uery? Sub,ueries, or nested ,ueries, are used to bring back a set of rows to be used by the parent ,uery. Depending on how the sub,uery is written, it can be e3ecuted once for the parent ,uery or it can be e3ecuted once for each row returned by the parent ,uery. #f the sub,uery is e3ecuted for each row of the parent, this is called a correlated su./uery. A correlated sub,uery can be easily identified if it contains any references to the parent sub,uery columns in its E)2$2 clause. Columns from the sub,uery cannot be referenced anywhere else in the parent ,uery. *he following e3ample demonstrates a non7correlated sub,uery. 2.g. Select 8 /rom C:S* Ehere T<AKA@K<JJAT #! 'Select ODA*2 /rom O$D2$ Ehere C:S*.C!: > O$D2$.C!: ( 05. What are the primitive operations common to all record management systems? Addition, deletion and modification. 07. &ame the .uffer in which all the commands that are typed in are stored >?&it% %uffer 0?. What are the unary operations in elational 6lge.ra? 4$OC2C*#O! and S2.2C*#O!. 5@. 6re the resulting relations of > E!Q,D and YE+& operation the same? !o. > E!Q,D5 Concatenation of every row in one relation with every row in another. YE+&5 Concatenation of rows from one relation and related rows from another. 51. What is !"#$ [1 &1L? *wo important pieces of $D% S architecture are the kernel, which is the software, and the data dictionary, which consists of the system7level data structures used by the kernel to manage the database Hou might think of an $D% S as an operating system 'or set of subsystems(, designed specifically for controlling data accessX its primary functions are storing,
<BB

retrieving, and securing data. An $D% S maintains its own list of authorized users and their associated privilegesX manages memory caches and pagingX controls locking for concurrent resource usageX dispatches and schedules user re,uestsX and manages space usage within its table7space structures . 52. &ame the su.3systems of a !"#$ #KO, Security, .anguage 4rocessing, 4rocess Control, Storage anagement, .ogging and $ecovery, Distribution Control, *ransaction Control, emory anagement, .ock anagement 53. Which part of the !"#$ ta'es care of the data dictionary? )ow Data dictionary is a set of tables and database ob;ects that is stored in a special area of the database and maintained e3clusively by the kernel. 5*. What is the jo. of the information stored in data3dictionary? *he information in the data dictionary validates the e3istence of the ob;ects, provides access to them, and maps the actual physical storage location. 5-. &ot only !"#$ ta'es care of locating data it also determines an optimal access path to store or retrieve the data 50. )ow do you communicate with an !"#$? Hou communicate with an $D% S using Structured Luery .anguage 'SL.( 55. !efine $AL and state the differences .etween $AL and other conventional programming Languages SL. is a nonprocedural language that is designed specifically for data access operations on normalized relational database structures. *he primary difference between SL. and other conventional programming languages is that SL. statements specify what data operations should be performed rather than how to perform them. 57. &ame the three major set of files on dis' that compose a data.ase in Eracle *here are three ma;or sets of files on disk that compose a database. All the files are binary. *hese are Database files Control files $edo logs *he most important of these are the database files where the actual data resides. *he control files and the redo logs support the functioning of the architecture itself. All three sets of files must be present, open, and available to Oracle for any data on the database to be useable. Eithout these files, you cannot access the database, and the database administrator might have to recover some or all of the database using a backup, if there is one. 5?. What is an Eracle +nstance?
<B=

*he Oracle system processes, also known as Oracle background processes, provide functions for the user processesgfunctions that would otherwise be done by the user processes themselves Oracle database7wide system memory is known as the S"A, the system glo.al area or shared glo.al area. *he data and control structures in the S"A are shareable, and all the Oracle background processes and user processes can use them. *he combination of the S"A and the Oracle background processes is known as an Eracle instance 7@. What are the four Eracle system processes that must always .e up and running for the data.ase to .e usea.le *he four Oracle system processes that must always be up and running for the database to be useable include !"W 'Database Eriter(, L=W '.og Eriter(, $#E& 'System onitor(, and >#E& '4rocess onitor(. 71. What are data.ase files% control files and log files. )ow many of these files should a data.ase have at least? Why? !ata.ase <iles *he database files hold the actual data and are typically the largest in size. Depending on their sizes, the tables 'and other ob;ects( for all the user accounts can go in one database filegbut thatTs not an ideal situation because it does not make the database structure very fle3ible for controlling access to storage for different users, putting the database on different disk drives, or backing up and restoring ;ust part of the database. Hou must have at least one database file but usually, more than one files are used. #n terms of accessing and using the data in the tables and other ob;ects, the number 'or location( of the files is immaterial. *he database files are fi3ed in size and never grow bigger than the size at which they were created ,ontrol <iles *he control files and redo logs support the rest of the architecture. Any database must have at least one control file, although you typically have more than one to guard against loss. *he control file records the name of the database, the date and time it was created, the location of the database and redo logs, and the synchronization information to ensure that all three sets of files are always in step. 2very time you add a new database or redo log file to the database, the information is recorded in the control files. edo Logs Any database must have at least two redo logs. *hese are the ;ournals for the databaseX the redo logs record all changes to the user ob;ects or system ob;ects. #f any type of failure occurs, the changes recorded in the redo logs can be used to bring the database to a consistent state without losing any committed transactions. #n the case of non7data loss failure, Oracle can apply the information in the redo logs automatically without intervention from the D%A. *he redo log files are fi3ed in size and never grow dynamically from the size at which they were created.
<B?

72. What is EW+!? *he $OE#D is a uni,ue database7wide physical address for every row on every table. Once assigned 'when the row is first inserted into the database(, it never changes until the row is deleted or the table is dropped. *he $OE#D consists of the following three components, the combination of which uni,uely identifies the physical storage location of the row. Oracle database file number, which contains the block with the rows Oracle block address, which contains the row *he row within the block 'because each block can hold many rows( *he $OE#D is used internally in inde3es as a ,uick means of retrieving rows with a particular key value. Application developers also use it in SL. statements as a ,uick way to access a row once they know the $OE#D 73. What is Eracle "loc'? ,an two Eracle "loc's have the same address? Oracle NformatsN the database files into a number of Oracle blocks when they are first createdgmaking it easier for the $D% S software to manage the files and easier to read data into the memory areas. *he block size should be a multiple of the operating system block size. $egardless of the block size, the entire block is not available for holding dataX Oracle takes up some space to manage the contents of the block. *his block header has a minimum size, but it can grow. *hese Oracle blocks are the smallest unit of storage. #ncreasing the Oracle block size can improve performance, but it should be done only when the database is first created. 2ach Oracle block is numbered se,uentially for each database file starting at <. *wo blocks can have the same block address if they are in different database files. 7*. What is data.ase Drigger? A database trigger is a 4.KSL. block that can defined to automatically e3ecute for insert, update, and delete statements against a table. *he trigger can e defined to e3ecute once for the entire statement or once for every row that is inserted, updated, or deleted. /or any one table, there are twelve events for which you can define database triggers. A database trigger can call database procedures that are also written in 4.KSL.. 7-. &ame two utilities that Eracle provides% which are use for .ac'up and recovery. Along with the $D% S software, Oracle provides two utilities that you can use to back up and restore the database. *hese utilities are 1xport and +mport. *he 1xport utility dumps the definitions and data for the specified part of the database to an operating system binary file. *he +mport utility reads the file produced by an e3port, recreates the definitions of ob;ects, and inserts the data #f 23port and #mport are used as a means of backing up and recovering the database, all the changes made to the database cannot be recovered since the e3port was performed. *he best you can do is recover the database to the time when the e3port was last performed. 70. What are stored3procedures? 6nd what are the advantages of using them.
<BF

Stored procedures are database ob;ects that perform a user defined operation. A stored procedure can have a set of compound SL. statements. A stored procedure e3ecutes the SL. commands and returns the result to the client. Stored procedures are used to reduce network traffic. 75. )ow are exceptions handled in >LG$AL? =ive some of the internal exceptionsW name 4.KSL. e3ception handling is a mechanism for dealing with run7time errors encountered during procedure e3ecution. :se of this mechanism enables e3ecution to continue if the error is not severe enough to cause procedure termination. *he e3ception handler must be defined within a subprogram specification. 2rrors cause the program to raise an e3ception with a transfer of control to the e3ception7handler block. After the e3ception handler e3ecutes, control returns to the block in which the handler was defined. #f there are no more e3ecutable statements in the block, control returns to the caller. Qser3!efined 1xceptions 4.KSL. enables the user to define e3ception handlers in the declarations area of subprogram specifications. :ser accomplishes this by naming an e3ception as in the following e3ample5 otMfailure 2GC24*#O!X #n this case, the e3ception name is otMfailure. Code associated with this handler is written in the 2GC24*#O! specification area as follows5 2GC24*#O! when O*M/A#.:$2 then outMstatusMcode 5> gMoutMstatusMcodeX outMmsg 5> gMoutMmsgX *he following is an e3ample of a subprogram e3ception5 2GC24*#O! when !OMDA*AM/O:!D then gMoutMstatusMcode 5> T/A#.TX $A#S2 otMfailureX Eithin this e3ception is the $A#S2 statement that transfers control back to the otMfailure e3ception handler. *his techni,ue of raising the e3ception is used to invoke all user7 defined e3ceptions. $ystem3!efined 1xceptions 23ceptions internal to 4.KSL. are raised automatically upon error. !OMDA*AM/O:!D is a system7defined e3ception. *able below gives a complete list of internal e3ceptions. >LG$AL internal exceptions. 01cepti!n Na(e C:$SO$MA.$2ADHMO42! D:4M+A.MO!M#!D2G #!+A.#DMC:$SO$ #!+A.#DM!: %2$ .O"#!MD2!#2D
<BD

Orac2e 0rr!r O$A7A?=<< O$A7AAAA< O$A7A<AA< O$A7A<F-O$A7A<A<F

!OMDA*AM/O:!D !O*M.O""2DMO! 4$O"$A M2$$O$ S*O$A"2M2$$O$ *# 2O:*MO!M$2SO:$C2 *OOM A!HM$OES *$A!SAC*#O!M%AC_2DMO:* +A.:2M2$$O$ f2$OMD#+#D2

O$A7A<BA@ O$A7A<A<O$A7A?=A< O$A7A?=AA O$A7AAA=< O$A7A<B-O$A7AAA?< O$A7A?=AO$A7A<BF?

#n addition to this list of e3ceptions, there is a catch7all e3ception named ED)1 $ that traps all errors for which specific error handling has not been established. 77. !oes >LG$AL support KoverloadingK? 1xplain *he concept of overloading in 4.KSL. relates to the idea that you can define procedures and functions with the same name. 4.KSL. does not look only at the referenced name, however, to resolve a procedure or function call. *he count and data types of formal parameters are also considered. 4.KSL. also attempts to resolve any procedure or function calls in locally defined packages before looking at globally defined packages or internal functions. *o further ensure calling the proper procedure, you can use the dot notation. 4refacing a procedure or function name with the package name fully ,ualifies any procedure or function reference. 7?. Da.les derived from the 1 ! a( Are totally unnormalised b( Are always in <!/ c( Can be further denormalised d( ay have multi7valued attributes 'b( Are always in <!/ ?@. $purious tuples may occur due to i. "ad normaliCation ii. Dheta joins iii. Qpdating ta.les from join a( i U ii b( ii U iii c( i U iii d( ii U iii 'a( i U iii because theta ;oins are ;oins made on keys that are not primary keys. ?1. 6 " , is a set of attri.utes. Dhe functional dependency is as follows 6" 3V " 6, 3V , , 3V " a( is in <!/
<BJ

b( is in -!/ c( is in @!/ d( is in %C!/ 'a( is in <!/ since 'AC(9 > ] A, %, C^ hence AC is the primary key. Since C % is a /D given, where neither C is a _ey nor % is a prime attribute, this it is not in @!/. /urther % is not functionally dependent on key AC thus it is not in -!/. *hus the given /Ds is in <!/. ?2. +n mapping of 1 ! to !<! a( entities in 2$D should correspond to an e3isting entityKstore in D/D b( entity in D/D is converted to attributes of an entity in 2$D c( relations in 2$D has < to < correspondence to processes in D/D d( relationships in 2$D has < to < correspondence to flows in D/D 'a( entities in 2$D should correspond to an e3isting entityKstore in D/D ?3. 6 dominant entity is the entity a( on the ! side in a < 5 ! relationship b( on the < side in a < 5 ! relationship c( on either side in a < 5 < relationship d( nothing to do with < 5 < or < 5 ! relationship 'b( on the < side in a < 5 ! relationship ?*. $elect W&E D)W% ,Q$DE#1 <rom ,Q$D^!DL$ Where 1=+E& I W&W Erder "y ,Q$DE#1 Qnion $elect W16$DW% ,Q$DE#1 <rom ,Q$D^!DL$ Where 1=+E& I W1W Erder "y ,Q$DE#1 *he above is a( !ot an error b( 2rror 7 the string in single ,uotes T!O$*)T and TSO:*)T c( 2rror 7 the string should be in double ,uotes d( 2rror 7 O$D2$ %H clause 'd( 2rror 7 the O$D2$ %H clause. Since O$D2$ %H clause cannot be used in :!#O!S ?-. What is $torage #anager? #t is a program module that provides the interface between the low7level data stored in database, application programs and ,ueries submitted to the system. ?0. What is "uffer #anager? #t is a program module, which is responsible for fetching data from disk storage into main memory and deciding what data to be cache in memory. ?5. What is Dransaction #anager?
<=A

#t is a program module, which ensures that database, remains in a consistent state despite system failures and concurrent transaction e3ecution proceeds without conflicting. ?7. What is <ile #anager? #t is a program module, which manages the allocation of space on disk storage and data structure used to represent information stored on a disk. ??. What is 6uthoriCation and +ntegrity manager? #t is the program module, which tests for the satisfaction of integrity constraint and checks the authority of user to access data. 1@@. What are stand3alone procedures? 4rocedures that are not part of a package are known as stand7alone because they independently defined. A good e3ample of a stand7alone procedure is one written in a SL.8/orms application. *hese types of procedures are not available for reference from other Oracle tools. Another limitation of stand7alone procedures is that they are compiled at run time, which slows e3ecution. 1@1. What are cursors give different types of cursors. 4.KSL. uses cursors for all database information accesses statements. *he language supports the use two types of cursors +mplicit 1xplicit 1@2. What is cold .ac'up and hot .ac'up 2in case of Eracle4? ,old "ac'up: #t is copying the three sets of files 'database files, redo logs, and control file( when the instance is shut down. *his is a straight file copy, usually from the disk directly to tape. Hou must shut down the instance to guarantee a consistent copy. #f a cold backup is performed, the only option available in the event of data file loss is restoring all the files from the latest backup. All work performed on the database since the last backup is lost. )ot "ac'up: Some sites 'such as worldwide airline reservations systems( cannot shut down the database while making a backup copy of the files. *he cold backup is not an available option. So different means of backing up database must be used g the hot backup. #ssue a SL. command to indicate to Oracle, on a tablespace7by7tablespace basis, that the files of the tablespace are to backed up. *he users can continue to make full use of the files, including making changes to the data. Once the user has indicated that heKshe wants to back up the tablespace files, heKshe can use the operating system to copy those files to the desired backup destination. *he database must be running in A$C)#+2.O" mode for the hot backup option.
<=<

#f a data loss failure does occur, the lost database files can be restored using the hot backup and the online and offline redo logs created since the backup was done. *he database is restored to the most consistent state without any loss of committed transactions. 1@3. What are 6rmstrong rules? )ow do we say that they are complete andGor sound *he well7known inference rules for /Ds $efle3ive rule 5 #f H is subset or e,ual to G then G H. Augmentation rule5 #f G H then Gf Hf. *ransitive rule5 #f ]G H, H f^ then G f. Decomposition rule 5 #f G Hf then G H. :nion or Additive rule5 #f ]G H, G f^ then G Hf. 4seudo *ransitive rule 5 #f ]G H, EH f^ then EG f. Of these the first three are known as Amstrong $ules. *hey are sound because it is enough if a set of /Ds satisfy these three. *hey are called complete because using these three rules we can generate the rest all inference rules. 1@*. )ow can you find the minimal 'ey of relational schema? inimal key is one which can identify each tuple of the given relation schema uni,uely. /or finding the minimal key it is re,uired to find the closure that is the set of all attributes that are dependent on any given set of attributes under the given set of functional dependency. 1l5o9 @ Determining G9, closure for G, given set of /Ds / <. Set G9 > G -. Set Old G9 > G9 @. /or each /D H f in / and if H belongs to G 9 then add f 9 to G B. $epeat steps - and @ until Old G9 > G9 1l5o9@@ Determining minimal _ for relation schema $, given set of /Ds / <. Set _ to $ that is make _ a set of all attributes in $ -. /or each attribute A in _ a. Compute '_ & A(9 with respect to / b. #f '_ & A(9 > $ then set _ > '_ & A(9 1@-. What do you understand .y dependency preservation? "iven a relation $ and a set of /Ds /, dependency preservation states that the closure of the union of the pro;ection of / on each decomposed relation $i is e,ual to the closure of /. i.e.,
<=-

''$<'/(( : I : '$n'/(((9 > /9 if decomposition is not dependency preserving, then some dependency is lost in the decomposition. 1@0. What is meant .y >roactive% etroactive and $imultaneous Qpdate. >roactive Qpdate: *he updates that are applied to database before it becomes effective in real world . etroactive Qpdate: *he updates that are applied to database after it becomes effective in real world . $imulatneous Qpdate: *he updates that are applied to database at the same time when it becomes effective in real world . 1@5. What are the different types of YE+& operations? 1/ui Yoin: *his is the most common type of ;oin which involves only e,uality comparisions. *he disadvantage in this type of ;oin is that there

<=@

SQL
SL.
1. Which is the su.set of $AL commands used to manipulate Eracle !ata.ase structures% including ta.les? Data Definition .anguage 'DD.( 2. What operator performs pattern matching? .#_2 operator 3. What operator tests column for the a.sence of data? #S !:.. operator *. Which command executes the contents of a specified file? S*A$* RfilenameQ or bRfilenameQ -. What is the parameter su.stitution sym.ol used with +&$1 D +&DE command? U 0. Which command displays the $AL command in the $AL .uffer% and then executes it? $:! 5. What are the wildcards used for pattern matching? M for single character substitution and W for multi7character substitution 7. $tate true or false. 1Z+$D$% $E#1% 6&_ are operators in $AL. *rue ?. $tate true or false. UI% RV% ;I all denote the same operation. *rue 1@. What are the privileges that can .e granted on a ta.le .y a user to others? #nsert, update, delete, select, references, inde3, e3ecute, alter, all 11. What command is used to get .ac' the privileges offered .y the = 6&D command? $2+O_2 12. Which system ta.les contain information on privileges granted and privileges o.tained?
<=B

:S2$M*A%M4$#+SM AD2, :S2$M*A%M4$#+SM$2CD 13. Which system ta.le contains information on constraints on all the ta.les created? :S2$MCO!S*$A#!*S 1*. D Q&,6D1 D6"L1 1#>J !1L1D1 < E# 1#>J Will the outputs of the a.ove two commands differ? %oth will result in deleting all the rows in the table 2 4. 1-. What is the difference .etween D Q&,6D1 and !1L1D1 commands? *$:!CA*2 is a DD. command whereas D2.2*2 is a D . command. )ence D2.2*2 operation can be rolled back, but *$:!CA*2 operation cannot be rolled back. E)2$2 clause can be used with D2.2*2 and not with *$:!CA*2. 10. What command is used to create a ta.le .y copying the structure of another ta.le? Ans)er / C$2A*2 *A%.2 .. AS S2.2C* command 01p2anati!n / *o copy only the structure, the E)2$2 clause of the S2.2C* command should contain a /A.S2 statement as in the following. C$2A*2 *A%.2 !2E*A%.2 AS S2.2C* 8 /$O 2G#S*#!"*A%.2 E)2$2 <>-X #f the E)2$2 condition is true, then all the rows or rows satisfying the condition will be copied to the new table. 15. What will .e the output of the following /uery?

$1L1,D 1>L6,12D 6&$L6D12LD +#2 D +#2WUU 6D)1& UUW%WUW4% WUW4% W6&W% W99W4%W9W%WD EQ"L1W4 < E# !Q6LJ
*$O:%.2*)2*$O:%.2 17. What will .e the output of the following /uery? $1L1,D !1,E!12D 6&$L6D12W6W%W123*-057?@W%W1111111111W4% W1W%W_1$W% W&EW 4J Ans)er / !O 01p2anati!n / *he ,uery checks whether a given string is a numerical digit. 1?. What does the following /uery do? $1L1,D $6L 8 &BL2,E##%@4 < E# 1#>J *his displays the total salary of all employees. *he null values in the commission column will be replaced by A and added to salary. 2@. Which date function is used to find the difference .etween two dates? O!*)SM%2*E22!
<==

21. Why does the following command give a compilation error? ! E> D6"L1 (D6"L1^&6#1J +ariable names should start with an alphabet. )ere the table name starts with an TUT symbol. 22. What is the advantage of specifying W+D) = 6&D E>D+E& in the = 6&D command? *he privilege receiver can further grant the privileges heKshe has obtained from the owner to any other user. 23. What is the use of the ! E> option in the 6LD1 D6"L1 command? #t is used to drop constraints specified on the table. 2*. What is the value of XcommF and XsalF after executing the following /uery if the initial value of XsalF is 1@@@@? Q>!6D1 1#> $1D $6L I $6L 8 1@@@% ,E## I $6L9@.1J sal > <<AAA, comm > <AAA 2-. What is the use of !1$, in $AL? Ans)er / D2SC has two purposes. #t is used to describe a schema as well as to retrieve rows from table in descending order. 01p2anati!n / *he ,uery S2.2C* 8 /$O 2 4 O$D2$ %H 2!A 2 D2SC will display the output sorted on 2!A 2 in descending order. 20. What is the use of ,6$,6!1 ,E&$D 6+&D$? Ehen this clause is used with the D$O4 command, a parent table can be dropped even when a child table e3ists. 25. Which function is used to find the largest integer less than or e/ual to a specific value? /.OO$ 27. What is the output of the following /uery? $1L1,D D Q&,2123*.-057%324 < E# !Q6LJ <-AA

<A4 B AU?R@?<
<=?

I. SC;0$AS Da.le 1 : S4UDI0S 4!A 2 '+A$C)A$(, S4.AC2 '+A$C)A$(, CO:$S2 '+A$C)A$(, CCOS* '!: %2$( Da.le 2 : SO<4=A"0 4!A 2 '+A$C)A$(, *#*.2 '+A$C)A$(, D2+#! '!: %2$(, DCOS* '!: %2$(, SO.D '!: %2$( Da.le 3 : P"O>"A$$0" 4!A 2 '+A$C)A$(, DO% 'DA*2(, DOC 'DA*2(, S2G 'C)A$(, 4$O/< '+A$C)A$(, 4$O/- '+A$C)A$(, SA. '!: %2$( 4?C?*2 : 4!A 2 & 4rogrammer !ame, S4.AC2 & Study 4lace, CCOS* & Course Cost, D2+#! & Developed in, SCOS* & Software Cost, DCOS* & Development Cost, 4$O/< & 4roficiency < QU0"I0S / 1. <ind out the selling cost average for pac'ages developed in Eracle. 2. !isplay the names% ages and experience of all programmers. 3. !isplay the names of those who have done the >=!,6 course. *. What is the highest num.er of copies sold .y a pac'age? -. !isplay the names and date of .irth of all programmers .orn in 6pril. 0. !isplay the lowest course fee. 5. )ow many programmers have done the !,6 course. 7. )ow much revenue has .een earned through the sale of pac'ages developed in ,. ?. !isplay the details of software developed .y a'esh. 1@. )ow many programmers studied at >entafour. 11. !isplay the details of pac'ages whose sales crossed the -@@@ mar'. 12. <ind out the num.er of copies which should .e sold in order to recover the development cost of each pac'age. 13. !isplay the details of pac'ages for which the development cost has .een recovered. 1*. What is the price of costliest software developed in B"? 1-. )ow many pac'ages were developed in Eracle ? 10. )ow many programmers studied at > 6=6D)+? 15. )ow many programmers paid 1@@@@ to 1-@@@ for the course? 17. What is the average course fee? 1?. !isplay the details of programmers 'nowing ,.
<=F

'+A$C)A$(,

SCOS*

2@. )ow many programmers 'now either , or >ascal? 21. )ow many programmers donFt 'now , and ,88? 22. )ow old is the oldest male programmer? 23. What is the average age of female programmers? 2*. ,alculate the experience in years for each programmer and display along with their names in descending order. 2-. Who are the programmers who cele.rate their .irthdays during the current month? 20. )ow many female programmers are there? 25. What are the languages 'nown .y the male programmers? 27. What is the average salary? 2?. )ow many people draw -@@@ to 5-@@? 3@. !isplay the details of those who donFt 'now ,% ,88 or >ascal. 31. !isplay the costliest pac'age developed .y each programmer. 32. >roduce the following output for all the male programmers >rogrammer #r. 6rvind : has 1- years of experience D?E<: <. S2.2C* A+"'SCOS*( /$O SO/*EA$2 E)2$2 D2+#! > TO$AC.2TX -. S2.2C* 4!A 2,*$:!C' O!*)SM%2*E22!'SHSDA*2,DO%(K<-( NA"2N, *$:!C' O!*)SM%2*E22!'SHSDA*2,DOC(K<-( N2G42$#2!C2N /$O 4$O"$A 2$X @. S2.2C* 4!A 2 /$O S*:D#2S E)2$2 CO:$S2 > T4"DCATX B. S2.2C* AG'SO.D( /$O SO/*EA$2X =. S2.2C* 4!A 2, DO% /$O 4$O"$A 2$ E)2$2 DO% .#_2 TWA4$ WTX ?. S2.2C* #!'CCOS*( /$O S*:D#2SX F. S2.2C* CO:!*'8( /$O S*:D#2S E)2$2 CO:$S2 > TDCATX D. S2.2C* S: 'SCOS*8SO.D7DCOS*( /$O SO/*EA$2 "$O:4 %H D2+#! )A+#!" D2+#! > TCTX J. S2.2C* 8 /$O SO/*EA$2 E)2$2 4!A 2 > T$A_2S)TX <A. S2.2C* 8 /$O S*:D#2S E)2$2 S4.AC2 > T42!*A/O:$TX <<. S2.2C* 8 /$O SO/*EA$2 E)2$2 SCOS*8SO.D7DCOS* Q =AAAX <-. S2.2C* C2#.'DCOS*KSCOS*( /$O SO/*EA$2X <@. S2.2C* 8 /$O SO/*EA$2 E)2$2 SCOS*8SO.D Q> DCOS*X <B. S2.2C* AG'SCOS*( /$O SO/*EA$2 "$O:4 %H D2+#! )A+#!" D2+#! > T+%TX <=. S2.2C* CO:!*'8( /$O SO/*EA$2 E)2$2 D2+#! > TO$AC.2TX <?. S2.2C* CO:!*'8( /$O S*:D#2S E)2$2 S4.AC2 > T4$A"A*)#TX <F. S2.2C* CO:!*'8( /$O S*:D#2S E)2$2 CCOS* %2*E22! <AAAA A!D <=AAAX <D. S2.2C* A+"'CCOS*( /$O S*:D#2SX <J. S2.2C* 8 /$O 4$O"$A 2$ E)2$2 4$O/< > TCT O$ 4$O/- > TCTX
<=D

-A. S2.2C* 8 /$O 4$O"$A 2$ E)2$2 4$O/< #! 'TCT,T4ASCA.T( O$ 4$O/- #! 'TCT,T4ASCA.T(X -<. S2.2C* 8 /$O 4$O"$A 2$ E)2$2 4$O/< !O* #! 'TCT,TC99T( A!D 4$O/- !O* #! 'TCT,TC99T(X --. S2.2C* *$:!C' AG' O!*)SM%2*E22!'SHSDA*2,DO%(K<-(( /$O 4$O"$A 2$ E)2$2 S2G > T TX -@. S2.2C* *$:!C'A+"' O!*)SM%2*E22!'SHSDA*2,DO%(K<-(( /$O 4$O"$A 2$ E)2$2 S2G > T/TX -B. S2.2C* 4!A 2, *$:!C' O!*)SM%2*E22!'SHSDA*2,DOC(K<-( /$O 4$O"$A 2$ O$D2$ %H 4!A 2 D2SCX -=. S2.2C* 4!A 2 /$O 4$O"$A 2$ E)2$2 *OMC)A$'DO%,T O!T( > *OMC)A$'SHSDA*2,T O!T(X -?. S2.2C* CO:!*'8( /$O 4$O"$A 2$ E)2$2 S2G > T/TX -F. S2.2C* D#S*#!C*'4$O/<( /$O 4$O"$A 2$ E)2$2 S2G > T TX -D. S2.2C* A+"'SA.( /$O 4$O"$A 2$X -J. S2.2C* CO:!*'8( /$O 4$O"$A 2$ E)2$2 SA. %2*E22! =AAA A!D F=AAX @A. S2.2C* 8 /$O 4$O"$A 2$ E)2$2 4$O/< !O* #! 'TCT,TC9 9T,T4ASCA.T( A!D 4$O/- !O* #! 'TCT,TC99T,T4ASCA.T(X @<. S2.2C* 4!A 2,*#*.2,SCOS* /$O SO/*EA$2 E)2$2 SCOS* #! 'S2.2C* AG'SCOS*( /$O SO/*EA$2 "$O:4 %H 4!A 2(X @-.S2.2C* T r.T VV 4!A 2 VV T 7 has T VV *$:!C' O!*)SM%2*E22!'SHSDA*2,DOC(K<-( VV T years of e3perienceT [4rogrammer\ /$O 4$O"$A 2$ E)2$2 S2G > T T :!#O! S2.2C* T s.T VV 4!A 2 VV T 7 has T VV *$:!C ' O!*)SM%2*E22! 'SHSDA*2,DOC(K<-( VV T years of e3perienceT [4rogrammer\ /$O 4$O"$A 2$ E)2$2 S2G > T/TX

II . SC;0$A /
Da.le 1 : 2?FT D24*!O '!O* !:.. , !: %2$'-((, D!A 2 '+A$C)A$-'<B((, .OC '+A$C)A$-'<@( Da.le 2 : ?3F 2 4!O '!O* !:.. , !: %2$'B((, 2!A 2 '+A$C)A$-'<A((, CO% '+A$C)A$-'J((, "$ '!: %2$'B((, )#$2DA*2 'DA*2(, SA. '!: %2$'F,-((, CO '!: %2$'F,-((, D24*!O '!: %2$'-(( "$ is the empno of the employee whom the employee reports to. D24*!O is a foreign key. QU0"I0S
<=J

1. List all the employees who have at least one person reporting to them. 2. List the employee details if and only if more than 1@ employees are present in department no 1@. 3. List the name of the employees with their immediate higher authority. *. List all the employees who do not manage any one. -. List the employee details whose salary is greater than the lowest salary of an employee .elonging to deptno 2@. 0. List the details of the employee earning more than the highest paid manager. 5. List the highest salary paid for each jo.. 7. <ind the most recently hired employee in each department. ?. +n which year did most people join the company? !isplay the year and the num.er of employees. 1@. Which department has the highest annual remuneration .ill? 11. Write a /uery to display a X9F against the row of the most recently hired employee. 12. Write a correlated su.3/uery to list out the employees who earn more than the average salary of their department. 13. <ind the nth maximum salary. 1*. $elect the duplicate records 2 ecords% which are inserted% that already exist4 in the 1#> ta.le. 1-. Write a /uery to list the length of service of the employees 2of the form n years and m months4. D?E<: <. S2.2C* D#S*#!C*'A.2!A 2( /$O 2 4 A, 2 4 % E)2$2 A.2 4!O > %. "$X or S2.2C* 2!A 2 /$O 2 4 E)2$2 2 4!O #! 'S2.2C* "$ /$O 2 4(X -. S2.2C* 8 /$O 2 4 E)2$2 D24*!O #! 'S2.2C* D24*!O /$O 2 4 "$O:4 %H D24*!O )A+#!" CO:!*'2 4!O(Q<A A!D D24*!O><A(X @. S2.2C* A.2!A 2 N2 4.OH22N, %.2!A 2 N$24O$*S *ON /$O 2 4 A, 2 4 % E)2$2 A. "$>%.2 4!OX B. S2.2C* 8 /$O 2 4 E)2$2 2 4!O #! ' S2.2C* 2 4!O /$O 2 4 #!:S S2.2C* "$ /$O 2 4(X =. S2.2C* 8 /$O 2 4 E)2$2 SA. Q ' S2.2C* #!'SA.( /$O 2 4 "$O:4 %H D24*!O )A+#!" D24*!O>-A(X ?. S2.2C* 8 /$O 2 4 E)2$2 SA. Q ' S2.2C* AG'SA.( /$O 2 4 "$O:4 %H CO% )A+#!" CO% > T A!A"2$T (X F. S2.2C* CO%, AG'SA.( /$O 2 4 "$O:4 %H CO%X D. S2.2C* 8 /$O 2 4 E)2$2 'D24*!O, )#$2DA*2( #! 'S2.2C* D24*!O, AG')#$2DA*2( /$O 2 4 "$O:4 %H D24*!O(X J. S2.2C* *OMC)A$')#$2DA*2,THHHHT( NH2A$N, CO:!*'2 4!O( N!O. O/ 2 4.OH22SN /$O 2 4 "$O:4 %H *OMC)A$')#$2DA*2,THHHHT( )A+#!" CO:!*'2 4!O( > 'S2.2C* AG'CO:!*'2 4!O(( /$O 2 4 "$O:4 %H *OMC)A$')#$2DA*2,THHHHT((X
<?A

<A. S2.2C* D24*!O, .4AD'S: '<-8'SA.9!+.'CO ,A(((,<=( NCO 42!SA*#O!N /$O 2 4 "$O:4 %H D24*!O )A+#!" S: ' <-8'SA.9!+.'CO ,A((( > 'S2.2C* AG'S: '<-8'SA.9!+.'CO ,A(((( /$O 2 4 "$O:4 %H D24*!O(X <<. S2.2C* 2!A 2, )#$2DA*2, .4AD'T8T,D( N$2C2!*.H )#$2DN /$O 2 4 E)2$2 )#$2DA*2 > 'S2.2C* AG')#$2DA*2( /$O 2 4( :!#O! S2.2C* 2!A 2 !A 2, )#$2DA*2, .4AD'T T,<=( N$2C2!*.H )#$2DN /$O 2 4 E)2$2 )#$2DA*2 S> 'S2.2C* AG')#$2DA*2( /$O 2 4(X <-. S2.2C* 2!A 2,SA. /$O 2 4 2 E)2$2 SA. Q 'S2.2C* A+"'SA.( /$O 2 4 / E)2$2 2.D24*!O > /.D24*!O(X <@. S2.2C* 2!A 2, SA. /$O 2 4 A E)2$2 U! > 'S2.2C* CO:!* 'D#S*#!C*'SA.(( /$O 2 4 % E)2$2 A.SA.R>%.SA.(X <B. S2.2C* 8 /$O 2 4 A E)2$2 A.2 4!O #! 'S2.2C* 2 4!O /$O 2 4 "$O:4 %H 2 4!O )A+#!" CO:!*'2 4!O(Q<( A!D A.$OE#DS> #! '$OE#D((X <=. S2.2C* 2!A 2 N2 4.OH22N,*OMC)A$'*$:!C' O!*)SM%2*E22!'SHSDA*2,)#$2DA*2(K< -((VVT H2A$S TVV *OMC)A$'*$:!C' OD' O!*)SM%2*E22! 'SHSDA*2, )#$2DA*2(,<-(((VVT O!*)S T N.2!"*) O/ S2$+#C2N /$O 2 4X

<?<

Computer Net or!s Computer !etworks


1. What are the two types of transmission technology availa.le? 'i( %roadcast and 'ii( point7to7point 2. What is su.net? A generic term for section of a large networks usually separated by a bridge or router. 3. !ifference .etween the communication and transmission. *ransmission is a physical movement of information and concern issues like bit polarity, synchronisation, clock etc. Communication means the meaning full e3change of information between two communication media. *. What are the possi.le ways of data exchange? 'i( Simple3 'ii( )alf7duple3 'iii( /ull7duple3. -. What is $6>? Series of interface points that allow other computers to communicate with the other layers of network protocol stack. 0. What do you meant .y Ktriple ZK in &etwor's? *he function of 4AD '4acket Assembler Disassembler( is described in a document known as G.@. *he standard protocol has been defined between the terminal and the 4AD, called G.-DX another standard protocol e3ists between the 4AD and the network, called G.-J. *ogether, these three recommendations are often called Ntriple GN 5. What is frame relay% in which layer it comes? /rame relay is a packet switching technology. #t will operate in the data link layer. 7. What is terminal emulation% in which layer it comes? *elnet is also called as terminal emulation. #t belongs to application layer. ?. What is "eaconing? *he process that allows a network to self7repair networks problems. *he stations on the network notify the other stations on the ring when they are not receiving the transmissions. %eaconing is used in *oken ring and /DD# networks.
<?-

1@. What is redirector? $edirector is software that intercepts file or prints #KO re,uests and translates them into network re,uests. *his comes under presentation layer. 11. What is &1D"+E$ and &1D"1Q+? !2*%#OS is a programming interface that allows #KO re,uests to be sent to and received from a remote computer and it hides the networking hardware from applications. !2*%2:# is !et%#OS e3tended user interface. A transport protocol designed by icrosoft and #% for the use on small subnets. 12. What is 6+!? A method for providing fault tolerance by using multiple hard disk drives. 13. What is passive topology? Ehen the computers on the network simply listen and receive the signal, they are referred to as passive because they don1t amplify the signal in any way. 23ample for passive topology 7 linear bus. 1*. What is "router? )ybrid devices that combine the features of both bridges and routers. 1-. What is cladding? A layer of a glass surrounding the center fiber of glass inside a fiber7optic cable. 10. What is point3to3point protocol A communications protocol used to connect computers to remote networking services including #nternet service providers. 15. )ow =ateway is different from outers? A gateway operates at the upper levels of the OS# model and translates information between two completely different network architectures or data formats 17. What is attenuation? *he degeneration of a signal over distance on a network cable is called attenuation. 1?. What is #6, address? *he address for a device as it is identified at the edia Access Control ' AC( layer in the network architecture. AC address is usually stored in $O on the network adapter card and is uni,ue. 2@. !ifference .etween .it rate and .aud rate. %it rate is the number of bits transmitted during one second whereas baud rate refers to the number of signal units per second that are re,uired to represent those bits. .aud rate I .it rate G &
<?@

where ! is no7of7bits represented by each signal shift. 21. What is "andwidth? 2very line has an upper limit and a lower limit on the fre,uency of signals it can carry. *his limited range is called the bandwidth. 22. What are the types of Dransmission media? Signals are usually transmitted over some transmission media that are broadly classified in to two categories. a4 =uided #edia: *hese are those that provide a conduit from one device to another that include twisted7pair, coa3ial cable and fiber7optic cable. A signal traveling along any of these media is directed and is contained by the physical limits of the medium. *wisted7 pair and coa3ial cable use metallic that accept and transport signals in the form of electrical current. Optical fiber is a glass or plastic cable that accepts and transports signals in the form of light. .4 Qnguided #edia: *his is the wireless media that transport electromagnetic waves without using a physical conductor. Signals are broadcast either through air. *his is done through radio communication, satellite communication and cellular telephony. 23. What is >roject 7@2? #t is a pro;ect started by #222 to set standards to enable intercommunication between e,uipment from a variety of manufacturers. #t is a way for specifying functions of the physical layer, the data link layer and to some e3tent the network layer to allow for interconnectivity of ma;or .A! protocols. #t consists of the following5 DA-.< is an internetworking standard for compatibility of different .A!s and A!s across protocols. DA-.- .ogical link control '..C( is the upper sublayer of the data link layer which is non7architecture7specific, that is remains the same for all #2227defined .A!s. edia access control ' AC( is the lower sublayer of the data link layer that contains some distinct modules each carrying proprietary information specific to the .A! product being used. *he modules are 2thernet .A! 'DA-.@(, *oken bus .A! 'DA-.B(, *oken ring .A! 'DA-.=(. DA-.? is distributed ,ueue dual bus 'DLD%( designed to be used in A!s. 2*. What is >rotocol !ata Qnit? *he data unit in the ..C level is called the protocol data unit '4D:(. *he 4D: contains of four fields a destination service access point 'DSA4(, a source service access point 'SSA4(, a control field and an information field. DSA4, SSA4 are addresses used by the ..C to identify the protocol stacks on the receiving and sending machines that are generating and using the data. *he control field specifies whether the 4D: frame is a information frame '# 7 frame( or a supervisory frame 'S 7 frame( or a unnumbered frame ': 7 frame(.
<?B

2-. What are the different type of networ'ing G internetwor'ing devices? epeater: Also called a regenerator, it is an electronic device that operates only at physical layer. #t receives the signal in the network before it becomes weak, regenerates the original bit pattern and puts the refreshed copy back in to the link. "ridges: *hese operate both in the physical and data link layers of .A!s of same type. *hey divide a larger network in to smaller segments. *hey contain logic that allow them to keep the traffic for each segment separate and thus are repeaters that relay a frame only the side of the segment containing the intended recipent and control congestion. outers: *hey relay packets among multiple interconnected networks 'i.e. .A!s of different type(. *hey operate in the physical, data link and network layers. *hey contain software that enable them to determine which of the several possible paths is the best for a particular transmission. =ateways: *hey relay packets among networks that have different protocols 'e.g. between a .A! and a EA!(. *hey accept a packet formatted for one protocol and convert it to a packet formatted for another protocol before forwarding it. *hey operate in all seven layers of the OS# model. 20. What is +,#>? #C 4 is #nternet Control essage 4rotocol, a network layer protocol of the *C4K#4 suite used by hosts and gateways to send notification of datagram problems back to the sender. #t uses the echo test K reply to test whether a destination is reachable and responding. #t also handles both control and error messages. 25. What are the data units at different layers of the D,> G +> protocol suite? *he data unit created at the application layer is called a message, at the transport layer the data unit created is called either a segment or an user datagram, at the network layer the data unit created is called the datagram, at the data link layer the datagram is encapsulated in to a frame and finally transmitted as signals along the transmission media. 27. What is difference .etween 6 > and 6 >? *he address resolution protocol 'A$4( is used to associate the @- bit #4 address with the BD bit physical address, used by a host or a router to find the physical address of another host on its network by sending a A$4 ,uery packet that includes the #4 address of the receiver. *he reverse address resolution protocol '$A$4( allows a host to discover its #nternet address when it knows only its physical address. 2?. What is the minimum and maximum length of the header in the D,> segment and +> datagram?
<?=

*he header should have a minimum length of -A bytes and can have a ma3imum length of ?A bytes. 3@. What is the range of addresses in the classes of internet addresses? Class A A.A.A.A 7 <-F.-==.-==.-== Class % <-D.A.A.A 7 <J<.-==.-==.-== Class C <J-.A.A.A 7 --@.-==.-==.-== Class D --B.A.A.A 7 -@J.-==.-==.-== Class 2 -BA.A.A.A 7 -BF.-==.-==.-== 31. What is the difference .etween D<D> and <D> application layer protocols? *he *rivial /ile *ransfer 4rotocol '*/*4( allows a local host to obtain files from a remote host but does not provide reliability or security. #t uses the fundamental packet delivery services offered by :D4. *he /ile *ransfer 4rotocol '/*4( is the standard mechanism provided by *C4 K #4 for copying a file from one host to another. #t uses the services offer by *C4 and so is reliable and secure. #t establishes two connections 'virtual circuits( between the hosts, one for data transfer and another for control information. 32. What are major types of networ's and explain? Server7based network 4eer7to7peer network 4eer7to7peer network, computers can act as both servers sharing resources and as clients using the resources. Server7based networks provide centralized control of network resources and rely on server computers to provide security and network administration 33. What are the important topologies for networ's? "Q$ topology: #n this each computer is directly connected to primary network cable in a single line. 6dvantages: #ne3pensive, easy to install, simple to understand, easy to e3tend. $D6 topology: #n this all computers are connected using a central hub. 6dvantages: Can be ine3pensive, easy to install and reconfigure and easy to trouble shoot physical problems. +&= topology: #n this all computers are connected in loop. 6dvantages: All computers have e,ual access to network media, installation can be simple, and signal does not degrade as much as in other topologies because each computer regenerates it.
<??

3*. What is mesh networ'? A network in which there are multiple network links between computers to provide multiple paths for data to travel. 3-. What is difference .etween .ase.and and .road.and transmission? #n a baseband transmission, the entire bandwidth of the cable is consumed by a single signal. #n broadband transmission, signals are sent on multiple fre,uencies, allowing multiple signals to be sent simultaneously. 30. 1xplain -3*33 rule? #n a 2thernet network, between any two points on the network ,there can be no more than five network segments or four repeaters, and of those five segments only three of segments can be populated. 35. What #6Q? #n token $ing , hub is called ultistation Access :nit' A:(.

37. What is the difference .etween routa.le and non3 routa.le protocols? $outable protocols can work with a router and can be used to build large networks. !on7$outable protocols are designed to work on small, local networks and cannot be used with a router 3?. Why should you care a.out the E$+ eference #odel? #t provides a framework for discussing network operations and design. *@. What is logical lin' control? One of two sublayers of the data link layer of OS# reference model, as defined by the #222 DA- standard. *his sublayer is responsible for maintaining the link between computers when they are sending data across the physical network connection. *1. What is virtual channel? +irtual channel is normally a connection from one source to one destination, although multicast connections are also permitted. *he other name for virtual channel is virtual circuit. *2. What is virtual path? Along any transmission path from a given source to a given destination, a group of virtual circuits can be grouped together into what is called path. *3. What is pac'et filter? 4acket filter is a standard router e,uipped with some e3tra functionality. *he e3tra functionality allows every incoming or outgoing packet to be inspected. 4ackets meeting some criterion are forwarded normally. *hose that fail the test are dropped. **. What is traffic shaping?
<?F

One of the main causes of congestion is that traffic is often busy. #f hosts could be made to transmit at a uniform rate, congestion would be less common. Another open loop method to help manage congestion is forcing the packet to be transmitted at a more predictable rate. *his is called traffic shaping. *-. What is multicast routing? Sending a message to a group is called multicasting, and its routing algorithm is called multicast routing. *0. What is region? Ehen hierarchical routing is used, the routers are divided into what we will call regions, with each router knowing all the details about how to route packets to destinations within its own region, but knowing nothing about the internal structure of other regions. *5. What is silly window syndrome? #t is a problem that can ruin *C4 performance. *his problem occurs when data are passed to the sending *C4 entity in large blocks, but an interactive application on the receiving side reads < byte at a time. *7. What are !igrams and Drigrams? *he most common two letter combinations are called as digrams. e.g. th, in, er, re and an. *he most common three letter combinations are called as trigrams. e.g. the, ing, and, and ion. *?. 1xpand +!16. #D2A stands for #nternational Data 2ncryption Algorithm. -@. What is wide3mouth frog? Eide7mouth frog is the simplest known key distribution center '_DC( authentication protocol. -1. What is #ail =ateway? #t is a system that performs a protocol translation between different electronic mail delivery protocols. -2. What is +=> 2+nterior =ateway >rotocol4? #t is any routing protocol used within an autonomous system. -3. What is 1=> 21xterior =ateway >rotocol4? #t is the protocol the routers in neighboring autonomous systems use to identify the set of networks that can be reached within or via each autonomous system. -*. What is autonomous system? #t is a collection of routers under the control of a single administrative authority and that uses a common #nterior "ateway 4rotocol.
<?D

--. What is "=> 2"order =ateway >rotocol4? #t is a protocol used to advertise the set of networks that can be reached with in an autonomous system. %"4 enables this information to be shared with the autonomous system. *his is newer than 2"4 '23terior "ateway 4rotocol(. -0. What is =ateway3to3=ateway protocol? #t is a protocol formerly used to e3change routing information between #nternet core routers. -5. What is &BD 2&etwor' Birtual Derminal4? #t is a set of rules defining a very simple virtual terminal interaction. *he !+* is used in the start of a *elnet session. -7. What is a #ulti3homed )ost? #t is a host that has a multiple network interfaces and that re,uires multiple #4 addresses is called as a ulti7homed )ost. -?. What is [er.eros? #t is an authentication service developed at the assachusetts #nstitute of *echnology. _erberos uses encryption to prevent intruders from discovering passwords and gaining unauthorized access to files. 0@. What is E$><? #t is an #nternet routing protocol that scales well, can route traffic along multiple paths, and uses knowledge of an #nternetTs topology to make accurate routing decisions. 01. What is >roxy 6 >? #t is using a router to answer A$4 re,uests. *his will be done when the originating host believes that a destination is local, when in fact is lies beyond router. 02. What is $L+> 2$erial Line +nterface >rotocol4? #t is a very simple protocol used for transmission of #4 datagrams across a serial line. 03. What is +> 2 outing +nformation >rotocol4? #t is a simple protocol used to e3change information between the routers. 0*. What is source route? #t is a se,uence of #4 addresses identifying the route a datagram must follow. A source route may optionally be included in an #4 datagram header.

<?J

Operatin" S#stems
Operating Systems
/ollowing are a few basic ,uestions that cover the essentials of OS5 1. 1xplain the concept of eentrancy. #t is a useful, memory7saving techni,ue for multiprogrammed timesharing systems. A eentrant >rocedure is one in which multiple users can share a single copy of a program during the same period. $eentrancy has - key aspects5 *he program code cannot modify itself, and the local data for each user process must be stored separately. *hus, the permanent part is the code, and the temporary part is the pointer back to the calling program and local variables used by that program. 2ach e3ecution instance is called activation. #t e3ecutes the code in the permanent part, but has its own copy of local variablesKparameters. *he temporary part associated with each activation is the activation record. "enerally, the activation record is kept on the stack. *ote5 A reentrant procedure can be interrupted and called by an interrupting program, and still e3ecute correctly on returning to the procedure. 2. 1xplain "eladyWs 6nomaly. Also called /#/O anomaly. :sually, on increasing the number of frames allocated to a processT virtual memory, the process e3ecution is faster, because fewer page faults occur. Sometimes, the reverse happens, i.e., the e3ecution time increases even when more frames are allocated to the process. *his is %eladyTs Anomaly. *his is true for certain page reference patterns. 3. What is a .inary semaphore? What is its use? A binary semaphore is one, which takes only A and < as values. *hey are used to implement mutual e3clusion and synchronize concurrent processes. *. What is thrashing? #t is a phenomenon in virtual memory schemes when the processor spends most of its time swapping pages, rather than e3ecuting instructions. *his is due to an inordinate number of page faults. -. List the ,offmanWs conditions that lead to a deadloc'. utual 23clusion5 Only one process may use a critical resource at a time. )old U Eait5 A process may be allocated some resources while waiting for others. !o 4re7emption5 !o resource can be forcible removed from a process holding it.
<FA

Circular Eait5 A closed chain of processes e3ist such that each process holds at least one resource needed by another process in the chain. 0. What are short3% long3 and medium3term scheduling? .ong term scheduler determines which programs are admitted to the system for processing. #t controls the degree of multiprogramming. Once admitted, a ;ob becomes a process. edium term scheduling is part of the swapping function. *his relates to processes that are in a blocked or suspended state. *hey are swapped out of real7memory until they are ready to e3ecute. *he swapping7in decision is based on memory7 management criteria. Short term scheduler, also know as a dispatcher e3ecutes most fre,uently, and makes the finest7grained decision of which process should e3ecute ne3t. *his scheduler is invoked whenever an event occurs. #t may lead to interruption of one process by preemption. 5. What are turnaround time and response time? *urnaround time is the interval between the submission of a ;ob and its completion. $esponse time is the interval between submission of a re,uest, and the first response to that re,uest. 7. What are the typical elements of a process image? :ser data5 odifiable part of user space. ay include program data, user stack area, and programs that may be modified. :ser program5 *he instructions to be e3ecuted. System Stack5 2ach process has one or more .#/O stacks associated with it. :sed to store parameters and calling addresses for procedure and system calls. 4rocess control %lock '4C%(5 #nfo needed by the OS to control processes. ?. What is the Dranslation Loo'aside "uffer 2DL"4? #n a cached system, the base addresses of the last few referenced pages is maintained in registers called the *.% that aids in faster lookup. *.% contains those page7table entries that have been most recently used. !ormally, each virtual memory reference causes - physical memory accesses77 one to fetch appropriate page7table entry, and one to fetch the desired data. :sing *.% in7between, this is reduced to ;ust one physical memory access in cases of *.%7hit. 1@. What is the resident set and wor'ing set of a process? $esident set is that portion of the process image that is actually in real7memory at a particular instant. Eorking set is that subset of resident set that is actually needed for e3ecution. '$elate this to the variable7window size method for swapping techni,ues.( 11. When is a system in safe state?

<F<

*he set of dispatchable processes is in a safe state if there e3ists at least one temporal order in which all processes can be run to completion without resulting in a deadlock. 12. What is cycle stealing? Ee encounter cycle stealing in the conte3t of Direct emory Access 'D A(. 2ither the D A controller can use the data bus when the C4: does not need it, or it may force the C4: to temporarily suspend operation. *he latter techni,ue is called cycle stealing. !ote that cycle stealing can be done only at specific break points in an instruction cycle. 13. What is meant .y arm3stic'iness? #f one or a few processes have a high access rate to data on one track of a storage disk, then they may monopolize the device by repeated re,uests to that track. *his generally happens with most common device scheduling algorithms '.#/O, SS*/, C7 SCA!, etc(. )igh7density multisurface disks are more likely to be affected by this than low density ones. 1*. What are the stipulations of ,2 level security? C- level security provides for5 Discretionary Access Control #dentification and Authentication Auditing $esource reuse 1-. What is .usy waiting? *he repeated e3ecution of a loop of code while waiting for an event to occur is called busy7waiting. *he C4: is not engaged in any real productive activity during this period, and the process does not progress toward completion. 10. 1xplain the popular multiprocessor thread3scheduling strategies. Load $haring: 4rocesses are not assigned to a particular processor. A global ,ueue of threads is maintained. 2ach processor, when idle, selects a thread from this ,ueue. !ote that load .alancing refers to a scheme where work is allocated to processors on a more permanent basis. =ang $cheduling: A set of related threads is scheduled to run on a set of processors at the same time, on a <7to7< basis. Closely related threads K processes may be scheduled this way to reduce synchronization blocking, and minimize process switching. "roup scheduling predated this strategy. !edicated processor assignment: 4rovides implicit scheduling defined by assignment of threads to processors. /or the duration of program e3ecution, each program is allocated a set of processors e,ual in number to the number of threads in the program. 4rocessors are chosen from the available pool. !ynamic scheduling: *he number of thread in a program can be altered during the course of e3ecution.
<F-

15. When does the condition WrendeCvousW arise? #n message passing, it is the condition in which, both, the sender and receiver are blocked until the message is delivered. 17. What is a trap and trapdoor? *rapdoor is a secret undocumented entry point into a program used to grant access without normal methods of access authentication. A trap is a software interrupt, usually the result of an error condition. 1?. What are local and glo.al page replacements? .ocal replacement means that an incoming page is brought in only to the relevant processT address space. "lobal replacement policy allows any page frame from any process to be replaced. *he latter is applicable to variable partitions model only. 2@. !efine latency% transfer and see' time with respect to dis' +GE. Seek time is the time re,uired to move the disk arm to the re,uired track. $otational delay or latency is the time it takes for the beginning of the re,uired sector to reach the head. Sum of seek time 'if any( and latency is the access time. *ime taken to actually transfer a span of data is transfer time. 21. !escri.e the "uddy system of memory allocation. /ree memory is maintained in linked lists, each of e,ual sized blocks. Any such block is of size -6k. Ehen some memory is re,uired by a process, the block size of ne3t higher order is chosen, and broken into two. !ote that the two such pieces differ in address only in their kth bit. Such pieces are called buddies. Ehen any used block is freed, the OS checks to see if its buddy is also free. #f so, it is re;oined, and put into the original free7block linked7list. 22. What is time3stamping? #t is a techni,ue proposed by .amport, used to order events in a distributed system without the use of clocks. *his scheme is intended to order events consisting of the transmission of messages. 2ach system TiT in the network maintains a counter Ci. 2very time a system transmits a message, it increments its counter by < and attaches the time7stamp *i to the message. Ehen a message is received, the receiving system T;T sets its counter C; to < more than the ma3imum of its current value and the incoming time7 stamp *i. At each site, the ordering of messages is determined by the following rules5 /or messages 3 from site i and y from site ;, 3 precedes y if one of the following conditions holds....'a( if *iR*; or 'b( if *i>*; and iR;. 23. )ow are the waitGsignal operations for monitor different from those for semaphores? #f a process in a monitor signal and no task is waiting on the condition variable, the signal is lost. So this allows easier program design. Ehereas in semaphores, every operation affects the value of the semaphore, so the wait and signal operations should be perfectly balanced in the program.

<F@

2*. +n the context of memory management% what are placement and replacement algorithms? 4lacement algorithms determine where in available real7memory to load a program. Common methods are first7fit, ne3t7fit, best7fit. $eplacement algorithms are used when memory is full, and one process 'or part of a process( needs to be swapped out to accommodate a new program. *he replacement algorithm determines which are the partitions to be swapped out. 2-. +n loading programs into memory% what is the difference .etween load3time dynamic lin'ing and run3time dynamic lin'ing? /or load7time dynamic linking5 .oad module to be loaded is read into memory. Any reference to a target e3ternal module causes that module to be loaded and the references are updated to a relative address from the start base address of the application module. Eith run7time dynamic loading5 Some of the linking is postponed until actual reference during e3ecution. *hen the correct module is loaded and linked. 20. What are demand3 and pre3paging? Eith demand paging, a page is brought into memory only when a location on that page is actually referenced during e3ecution. Eith pre7paging, pages other than the one demanded by a page fault are brought in. *he selection of such pages is done based on common access patterns, especially for secondary memory devices. 25. >aging a memory management function% while multiprogramming a processor management function% are the two interdependent? Hes. 27. What is page canni.aliCing? 4age swapping or page replacements are called page cannibalizing. 2?. What has triggered the need for multitas'ing in >,s? #ncreased speed and memory capacity of microprocessors together with the support fir virtual memory and "rowth of client server computing 3@. What are the four layers that Windows &D have in order to achieve independence? )ardware abstraction layer _ernel Subsystems System Services. 31. What is $#>? *o achieve ma3imum efficiency and reliability a mode of operation known as symmetric multiprocessing is used. #n essence, with S 4 any process or threads can be assigned to any processor.
<FB

32. What are the 'ey o.ject oriented concepts used .y Windows &D? 2ncapsulation Ob;ect class and instance 33. +s Windows &D a full .lown o.ject oriented operating system? =ive reasons. !o Eindows !* is not so, because its not implemented in ob;ect oriented language and the data structures reside within one e3ecutive component and are not represented as ob;ects and it does not support ob;ect oriented capabilities . 3*. What is a draw.ac' of #BD? #t does not have the features like ability to support multiple processors virtual storage source level debugging 3-. What is process spawning? Ehen the OS at the e3plicit re,uest of another process creates a process, this action is called process spawning. 30. )ow many jo.s can .e run concurrently on #BD? <= ;obs 35. List out some reasons for process termination. !ormal completion *ime limit e3ceeded emory unavailable %ounds violation 4rotection error Arithmetic error *ime overrun #KO failure #nvalid instruction 4rivileged instruction Data misuse Operator or OS intervention 4arent termination. 37. What are the reasons for process suspension? swapping interactive user re,uest timing parent process re,uest 3?. What is process migration? #t is the transfer of sufficient amount of the state of process from one machine to
<F=

the target machine *@. What is mutant? #n Eindows !* a mutant provides kernel mode or user mode mutual e3clusion with the notion of ownership. *1. What is an idle thread? *he special thread a dispatcher will e3ecute when no ready thread is found. *2. What is <t!is'? #t is a fault tolerance disk driver for Eindows !*. *3. Ehat are the possible threads a thread can have` $eady Standby $unning Eaiting *ransition *erminated. **. What are rings in Windows &D? Eindows !* uses protection mechanism called rings provides by the process to implement separation between the user mode and kernel mode. *-. What is 1xecutive in Windows &D? #n Eindows !*, e3ecutive refers to the operating system code that runs in kernel mode. *0. What are the su.3components of +GE manager in Windows &D? !etwork redirectorK Server Cache manager. /ile systems !etwork driver Device driver *5. What are !!'s? &ame an operating system that includes this feature. DDks are device driver kits, which are e,uivalent to SD_s for writing device drivers. Eindows !* includes DDks. *7. What level of security does Windows &D meets? C- level security.

<F?

You might also like