Table of Contents Data Structures Aptitude.............................................................................3 C Aptitude..................................................................................................12 C++ Aptitude and OOPS.............................................................................75 Quantitative Aptitude...............................................................................104 UNIX Concepts.........................................................................................121 RDBMS Concepts.....................................................................................135 SQL..........................................................................................................153 Computer Networks.................................................................................161 Operating Systems...................................................................................169 2 Technical Aptitude Questions 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 nowledge 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? !ompiler Design, "perating System, Database #anagement System, Statistical analysis pacage, $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+ $etwor data model ) %raph ,ierarchical data model ) Trees *. +f you are using , language to implement the heterogeneous lin'ed list% what pointer type will you use? The heterogeneous lined list contains different data types in its nodes and we need a lin, 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? Two. "ne .ueue is used for actual storing of data and another for storing priorities. / Data Structures Aptitude
Technical Aptitude Questions 0. What is the data structures used to perform recursion? Stac. (ecause of its 0&1" *0ast &n 1irst "ut+ property it remembers its 2caller3 so nows whom to return when the function has to return. 'ecursion maes use of system stac for storing the return addresses of the function calls. 1very recursive function has its e/uivalent iterative 2non3recursive4 function. 4ven when such e.uivalent iterative procedures are written, e5plicit stac is to be used. 5. What are the notations used in 1valuation of 6rithmetic 1xpressions using prefix and postfix forms? 6olish and 'everse 6olish notations. 7. ,onvert the expression 226 8 "4 9 , : 2! : 14 ; 2< 8 =44 to e/uivalent >refix and >ostfix notations. 6refi5 $otation7 8 9 : ;A(! 9 D4 ; 1% 6ostfi5 $otation7 A( ; ! : D4 9 9 1% ; 8 ?. $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 e5change 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? 2> 0et us tae a tree with ? nodes *n@?+ &t will have only A *ie,?;>+ 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 ? B $ull (ranches Technical Aptitude Questions Straight merging, $atural merging, 6olyphase sort, Distribution of &nitial runs. 12. )ow many different trees are possi.le with 1@ nodes ? >C>B 1or e5ample, consider a tree with / nodes*n@/+, it will have the ma5imum combination of ? different *ie, 2 / 9 / @ ?+ trees. i ii iii iv v &n general7 +f there are n nodes% there exist 2 n -n different trees. 13. List out few of the 6pplication of tree data3structure? The manipulation of Arithmetic e5pression, Symbol Table construction, Synta5 analysis. 1*. List out few of the applications that ma'e use of #ultilin'ed $tructures? Sparse matri5, &nde5 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+ 0ined list 10. What is the type of the algorithm used in solving the 7 Aueens pro.lem? (actracing 15. +n an 6BL tree% at what condition the .alancing is to .e done? &f the 2pivotal value3 *or the 2,eight factor3+ is greater than > or less than )>. 17. What is the .uc'et siCe% when the overlapping and collision occur at same time? ? Technical Aptitude Questions "ne. &f there is only one entry possible in the bucet, when the collision occurs, there is no way to accommodate the colliding value. This results in the overlapping of values. 1?. Draverse the given tree using +norder% >reorder and >ostorder traversals. &norder 7 D , ( 4 A 1 ! & % D 6reorder7 A ( D , 4 ! 1 % & D 6ostorder7 , D 4 ( 1 & D % ! 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 general7 Dhere are 2 n -1 nodes in a full .inary tree. "y the method of elimination: 1ull binary trees contain odd number of nodes. So there cannot be full binary trees with E or >B nodes, so re=ected. Fith >/ nodes you can form a complete binary tree but not a full binary tree. So the correct answer is >?. Note: 1ull and !omplete 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? A A ( ! D 4 1 % , & D %iven tree7 > 2 / B ? Technical Aptitude Questions At location A > 2 / 9 9 B 9 9 ? 'oot 0!> '!> 0!2 '!2 0!/ '!/ 0!B '!B where 0!n means 0eft !hild of node n and '!n means 'ight !hild of node n 22. $ort the given values using Auic' $ort? A? GC G? EC E? AC ?? ?C B? Sorting taes place from the pivot value, which is the first value of the given elements, this is mared bold. The values at the left pointer and right pointer are indicated using 0 and ' respectively. 65 GC 0 G? EC E? AC ?? ?C B? ' Since pivot is not yet changed the same process is continued after interchanging the values at 0 and ' positions 65 B? G? 0 EC E? AC ?? ?C ' GC 65 B? ?C EC 0 E? AC ?? ' G? GC 65 B? ?C ?? E? 0 AC ' EC G? GC 65 B? ?C ?? AC ' E? 0 EC G? GC Fhen the 0 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 position9> and the other from pivot position;> to end. 60 0 B? ?C ?? ' 65 85 0 EC G? GC ' G Technical Aptitude Questions 55 0 B? ?C ' 60 65 70 ' EC 0 G? 85 50 0 B? ' 55 60 65 70 EC 0 G? ' 85 &n the ne5t pass we get the sorted form of the array. 45 50 55 60 65 70 75 80 85 23. <or the given graph% draw the !<$ and "<$? "<$: A H % , 6 4 # I D !<$: A H , 6 4 I # D % 2*. ,lassify the )ashing <unctions .ased on the various methods .y which the 'ey value is found. Direct method, Subtraction method, #odulo9Division method, Digit945traction method, #id9S.uare method, 1olding method, 6seudo9random method. 2-. What are the types of ,ollision esolution Dechni/ues and the methods used in each of the type? "pen addressing *closed hashing+, The methods used include7 "verflow bloc, !losed addressing *open hashing+ The methods used include7 0ined list, E A , H % 6 4 I # D The given graph7 Technical Aptitude Questions (inary treeJ 20. +n !"#$% what is the efficient data structure used in the internal storage representation? (; tree. (ecause in (; tree, all the data is stored only in leaf nodes, that maes searching easier. This corresponds to the records that shall be stored in leaf nodes. 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 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+ !omplete (inary Tree. "y the method of elimination: 1ull binary tree loses its nature when operations of insertions and deletions are done. 1or incomplete binary trees, e5tra storage is re.uired and overhead of $<00 node checing taes place. So complete binary tree is the better one since the property of complete binary tree is maintained even after operations lie additions and deletions are done on it. 2?. What is a spanning Dree? A spanning tree is a tree associated with a networ. 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 ept at its minimum. (ut it doesnFt mean that the distance between any two nodes involved in the minimum9spanning tree is minimum. K >> 9 ? G >K 2B B 9 A 9 E 9 >A 9 2C 22 GE K2 Technical Aptitude Questions 31. ,onvert the given graph with weighted edges to minimal spanning tree. the e.uivalent minimal spanning tree is7 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 0ined list is a linear one. According to Storage 0ined 0ist is a $on9linear one. 3*. !raw a .inary Dree for the expression : 6 9 " 3 2, 8 !4 9 2> G A4 >C > / 2 B ? B>C ACC 2CC BCC />C >B2> 2KE? A>2 9 : : A ( ; L ! 6 D Q > 2 / B ? B>C A>2 2CC />C Technical Aptitude Questions 3-. <or the following ,E"EL code% draw the "inary tree? C> ST<D4$TM'4!. C2 $A#4. C/ 1&'STM$A#4 6&! H*>C+. C/ 0ASTM$A#4 6&! H*>C+. C2 I4A'M"1MST<DI. C/ 1&'STMS4# 6&! HH. C/ S4!"$DMS4# 6&! HH. >> ST<D4$TM'4! $A#4 I4A'M"1MST<DI 1&'STM$A#4 0ASTM$A#4 1&'STMS4# S4!"$DMS4# C> C2 C2 C/ C/ C/ C/ Technical Aptitude Questions ! Aptitude Note : All the programs are tested under Turbo !L!;; compilers. &t is assumed that, 6rograms run under D"S environment, The underlying machine is an 5EA system, 6rogram is compiled using Turbo !L!;; compiler. The program output may depend on the information based on this assumptions *for e5ample sizeof*int+ @@ 2 may be assumed+. 6redict the output or error*s+ for the following7 1. void main24 H int const 9 pI-J printf2KLdK%8829p44J M Answer: !ompiler error7 !annot modify a constant value. Explanation7 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 Answer: mmmm aaaa nnnn Explanation7 sOiP, :*i;s+, :*s;i+, iOsP are all different ways of e5pressing the same idea. %enerally array name is the base address for that array. ,ere s is the base address. i is the >2 C Aptitude
Technical Aptitude Questions inde5 numberLdisplacement from the base address. So, indirecting it with : is same as sOiP. iOsP may be surprising. (ut in the case of ! 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 Answer: & hate < Explanation7 1or floating point numbers (float, double, long double) the values cannot be predicted e5actly. Depending on the number of bytes, the precession with of the value represented varies. 1loat taes B bytes and long double taes >C bytes. So float stores C.K with less precision than long double. Rule of Thumb: $ever compare or at9least 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 Answer: ? B / 2 > Explanation: Fhen static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. #ain is also treated lie 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 >/ Technical Aptitude Questions M Answer: 2 2 2 2 2 2 / B A ? Explanation: &nitially pointer c is assigned to both p and q. &n the first loop, since only q is incremented and not c , the value 2 will be printed ? times. &n second loop p itself is incremented. So the values 2 / B A ? will be printed. 0. main24 H extern int iJ iI2@J printf2KLdK%i4J M Answer: Lin'er 1rror 7 <ndefined symbol TMiT Explanation: e5tern 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 lining. (ut liner finds that no other variable of name i is available in any other program with memory space allocated for it. ,ence a liner 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 Answer: C C > / > Explanation : 0ogical operations always give a result of 1 or 0 . And also the logical A$D *UU+ operator has higher priority over the logical "' *VV+ operator. So the e5pression 2i++ && ++ && !++" is e5ecuted first. The result of this e5pression is C *9> UU 9> UU C @ C+. $ow the e5pression is C VV 2 which evaluates to > *because "' operator always gives > e5cept for 2C VV C3 combination9 for which it gives C+. So the value of m is >. The values of other variables are also incremented by >. 7. main24 H char 9pJ printf2KLd Ld K%siCeof29p4%siCeof2p44J >B Technical Aptitude Questions M Answer: > 2 Explanation: The sizeof*+ operator gives the number of bytes taen by its operand. 6 is a character pointer, which needs one byte for storing its value *a character+. ,ence sizeof*:p+ gives a value of >. Since it needs two bytes to store the address of the character pointer sizeof*p+ gives 2. ?. 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 Answer : three Explanation : The default case can be placed anywhere inside the loop. &t is e5ecuted only when all other cases doesnTt match. 1@. main24 H printf2KLxK%31RR*4J M Answer: fffC Explanation : 9> is internally represented as all >Ts. Fhen left shifted four times the least significant B bits are filled with CTs.The W5 format specifier specifies that the integer value be printed as a he5adecimal value. 11. main24 H char stringNOIK)ello WorldKJ display2string4J M >? Technical Aptitude Questions void display2char 9string4 H printf2KLsK%string4J M Answer: ,ompiler 1rror : Type mismatch in redeclaration of function display Explanation : &n third line, when the function #ispl$% is encountered, the compiler doesnTt now anything about the function display. &t assumes the arguments and return types to be integers, *which is the default type+. Fhen 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 Answer: c@2X Explanation: ,ere unary minus *or negation+ operator is used twice. Same maths rules applies, ie. minus : minus@ plus. 'ote: ,owever you cannot give lie 992. (ecause 99 operator can only be applied to variables as a #e(rement operator *eg., i99+. 2 is a constant and not a variable. 13. Tdefine int char main24 H int iI0-J printf2KsiCeof2i4ILdK%siCeof2i44J M Answer: sizeof*i+@> Explanation: Since the Ydefine replaces the string int by the macro (h$r 1*. main24 H int iI1@J iIUiV1*J printf2KiILdK%i4J M Answer: i@C >A Technical Aptitude Questions Explanation: &n the e5pression )i*1+ , $"T *S+ operator has more precedence than 2 Q3 symbol. ) is a unary logical operator. Si *S>C+ is C *not of true is false+. CQ>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 Answer: GG Explanation: p is pointing to character TZnT. str> is pointing to character TaT ;;:p. Np is pointing to TZnT and that is incremented by one.N the AS!&& value of TZnT is >C, which is then incremented to >>. The value of ;;:p is >>. ;;:str>, str> is pointing to TaT that is incremented by > and it becomes TbT. AS!&& value of TbT is KE. $ow performing *>> ; KE ) /2+, we get GG*N#N+X So we get the output GG 77 N#N *Ascii is GG+. 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 Answer: Some%arbage-alue999> Explanation: p@UaO2PO2PO2P you declare only two 2D arrays, but you are trying to access the third 2D*which you are not declared+ it will print garbage values. :.@:::a starting address of a is assigned integer pointer. $ow . is pointing to starting address of a. &f you print :., it will print first element of /D array. 15. TincludeRstdio.hV main24 >G Technical Aptitude Questions H struct xx H int xI3J char nameNOIKhelloKJ MJ struct xx 9sJ printf2KLdK%s3Vx4J printf2KLsK%s3Vname4J M Answer: !ompiler 4rror Explanation: Iou 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 Answer: !ompiler 4rror Explanation: The structure yy is nested within structure 55. ,ence, the elements are of yy are to be accessed through the instance of structure 55, which needs an instance of yy to be nown. &f the instance is created after defining the structure the compiler will not now about the instance relative to 55. ,ence for nested structure yy you have to declare member. 1?. main24 H printf2KPna.K4J printf2KP.siK4J printf2KPrhaK4J M Answer: hai >E Technical Aptitude Questions Explanation: Zn 9 newline Zb 9 bacspace Zr 9 linefeed 2@. main24 H int iI-J printf2KLdLdLdLdLdLdK%i88%i33%88i%33i%i4J M Answer: B??B? Explanation: The arguments in a function call are pushed into the stac from left to right. The evaluation is by popping out from the stac. 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 Answer: AB Explanation: the macro call s.uare*B+ will substituted by B:B so the e5pression becomes i @ ABLB:B . Since L and : has e.ual priority the e5pression will be evaluated as *ABLB+:B i.e. >A:B @ AB
22. main24 H char 9pIKhai friendsK%9p1J p1IpJ while29pUIWP@W4 889p88J printf2KLs LsK%p%p14J M Answer: ib=Sgs=foet Explanation: ;;:p;; will be parse in the given order :p that is value at the location currently pointed by p will be taen ;;:p the retrieved value will be incremented when X is encountered the location will be incremented that is p;; will be e5ecuted >K Technical Aptitude Questions ,ence, in the while loop initial value pointed by p is 2h3, which is changed to 2i3 by e5ecuting ;;:p and pointer moves to point, 2a3 which is similarly changed to 2b3 and so on. Similarly blan space is converted to 2S3. Thus, we obtain value in p becomes [ib=S gs=foet\ and since p reaches 2ZC3 and p> points to p thus p>doesnot print anything. 23. Tinclude Rstdio.hV Tdefine a 1@ main24 H Tdefine a -@ printf2KLdK%a4J M Answer: ?C Explanation: The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taen. 2*. Tdefine clrscr24 1@@ main24 H clrscr24J printf2KLdPnK%clrscr244J M Answer: >CC Explanation: 6reprocessor e5ecutes as a seperate pass before the e5ecution of the compiler. So te5tual replacement of clrscr*+ to >CC occurs.The input program to compiler loos lie this 7 main*+ ] >CCX printf*NWdZnN,>CC+X ^ 'ote: >CCX is an e5ecutable statement but with no action. So it doesnTt give any problem 2-. main24 H printf2KLpK%main4J M Answer: Some address will be printed. Explanation: 2C Technical Aptitude Questions 1unction names are =ust addresses *=ust lie 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. They are printed as he5adecimal numbers. 2G+ main*+ ] clrscr*+X ^ clrscr*+X Answer: $o outputLerror Explanation: The 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+. 2E+ enum colors ](0A!_,(0<4,%'44$^ main*+ ]
printf*NWd..Wd..WdN,(0A!_,(0<4,%'44$+X
return*>+X ^ Answer: C..>..2 Explanation: enum assigns numbers starting from C, if not e5plicitly defined. 2K+ void main*+ ] char far :farther,:farthestX
^ Answer: B..2 Explanation: the second pointer is of char type and not a far pointer /C+ main*+ ] int i@BCC,=@/CCX printf*NWd..WdN+X 2> Technical Aptitude Questions ^ Answer: BCC../CC Explanation: printf taes the values of the first two assignments of the program. Any number of printfTs may be given. All of them tae only the first two values. &f more number of assignments given in the program,then printf will tae garbage values. />+ main*+ ] char :pX p@N,elloNX printf*NWcZnN,:U:p+X ^ Answer: , Explanation: : is a dereference operator U is a reference operator. They can be applied any number of times provided it is meaningful. ,ere p points to the first character in the string N,elloN. :p dereferences it and so its value is ,. Again U references it to an address and : dereferences it to the value ,. /2+ main*+ ] int i@>X while *iR@?+ ] printf*NWdN,i+X if *iQ2+ goto hereX i;;X ^ ^ fun*+ ] here7 printf*N66N+X ^ Answer: !ompiler error7 <ndefined label ThereT in function main Explanation: 0abels have functions scope, in other words The scope of the labels is limited to functions . The label ThereT is available in function fun*+ ,ence it is not visible in function main. 22 Technical Aptitude Questions //+ main*+ ] static char namesO?PO2CP@]NpascalN,NadaN,NcobolN,NfortranN,NperlN^X int iX char :tX t@namesO/PX namesO/P@namesOBPX namesOBP@tX for *i@CXiR@BXi;;+ printf*NWsN,namesOiP+X ^ Answer: !ompiler error7 0value re.uired in function main Explanation: Array names are pointer constants. So it cannot be modified. /B+ void main*+ ] int i@?X printf*NWdN,i;; ; ;;i+X ^ Answer: "utput !annot be predicted e5actly. Explanation: Side effects are involved in the evaluation of i /?+ void main*+ ] int i@?X printf*NWdN,i;;;;;i+X ^ Answer: !ompiler 4rror Explanation: The e5pression i;;;;;i is parsed as i ;; ;; ; i which is an illegal combination of operators.
/A+ YincludeRstdio.hQ main*+ ] int i@>,=@2X switch*i+ ] case >7 printf*N%""DN+X breaX 2/ Technical Aptitude Questions case =7 printf*N(ADN+X breaX ^ ^ Answer: !ompiler 4rror7 !onstant e5pression re.uired in function main. Explanation: The case statement can have only constant e5pressions *this implies that we cannot use variable names directly so an error+. 'ote: 4numerated types can be used in case statements. /G+ main*+ ] int iX printf*NWdN,scanf*NWdN,Ui++X LL value >C is given as input here ^ Answer: > Explanation: Scanf returns number of items successfully read and not >LC. ,ere >C is given as input which should have been scanned successfully. So number of items read is >. /E+ Ydefine f*g,g2+ gYYg2 main*+ ] int var>2@>CCX printf*NWdN,f*var,>2++X ^ Answer: >CC /K+ main*+ ] int i@CX
for*Xi;;Xprintf*NWdN,i++ X printf*NWdN,i+X ^ Answer: > Explanation: before entering into the for loop the checing condition is NevaluatedN. ,ere it evaluates to C *false+ and comes out of the loop, and i is incremented *note the semicolon after the for loop+. 2B Technical Aptitude Questions BC+ YincludeRstdio.hQ main*+ ] char sOP@]TaT,TbT,TcT,TZnT,TcT,TZCT^X char :p,:str,:str>X p@UsO/PX str@pX str>@sX printf*NWdN,;;:p ; ;;:str>9/2+X ^ Answer: # Explanation: p is pointing to character TZnT.str> is pointing to character TaT ;;:p meAnswer7Np is pointing to TZnT and that is incremented by one.N the AS!&& value of TZnT is >C. then it is incremented to >>. the value of ;;:p is >>. ; ;:str> meAnswer7Nstr> is pointing to TaT that is incremented by > and it becomes TbT. AS!&& value of TbT is KE. both >> and KE is added and result is subtracted from /2. i.e. *>>;KE9/2+@GG*N#N+X B>+ YincludeRstdio.hQ main*+ ] struct 55 ] int 5@/X char nameOP@NhelloNX ^X struct 55 :s@malloc*sizeof*struct 55++X printf*NWdN,s9Q5+X printf*NWsN,s9Qname+X ^ Answer: !ompiler 4rror Explanation: &nitialization should not be done for structure members inside the structure declaration B2+ YincludeRstdio.hQ main*+ ] struct 55 ] int 5X 2? Technical Aptitude Questions struct yy ] char sX struct 55 :pX ^X struct yy :.X ^X ^ Answer: !ompiler 4rror Explanation: in the end of nested structure yy a member have to be declared. B/+ main*+ ] e5tern int iX i@2CX printf*NWdN,sizeof*i++X ^ Answer: 0iner error7 undefined symbol TMiT. Explanation: e5tern declaration specifies that the variable i is defined somewhere else. The compiler passes the e5ternal variable to be resolved by the liner. So compiler doesnTt find an error. During lining the liner searches for the definition of i. Since it is not found the liner flags an error. BB+ main*+ ] printf*NWdN, out+X ^ int out@>CCX Answer: !ompiler error7 undefined symbol out in function main. Explanation: The rule is that a variable is available for use from the point of declaration. 4ven though a is a global variable, it is not available for main. ,ence an error. B?+ main*+ ] e5tern outX printf*NWdN, out+X ^ int out@>CCX Answer: 2A Technical Aptitude Questions >CC Explanation: This is the correct way of writing the previous program.
BA+ main*+ ] show*+X ^ void show*+ ] printf*N&Tm the greatestN+X ^ Answer: !ompier error7 Type mismatch in redeclaration of show. Explanation: Fhen the compiler sees the function show it doesnTt now 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. The solutions are as follows7 >. declare void show*+ in main*+ . 2. define show*+ before main*+. /. declare e5tern void show*+ before the use of show*+.
BG+ main* + ] int aO2PO/PO2P @ ]]]2,B^,]G,E^,]/,B^^,]]2,2^,]2,/^,]/,B^^^X printf*[Wu Wu Wu Wd Zn\,a,:a,::a,:::a+X printf*[Wu Wu Wu Wd Zn\,a;>,:a;>,::a;>,:::a;>+X ^ Answer: >CC, >CC, >CC, 2 >>B, >CB, >C2, / Explanation: The given array is a /9D one. &t can also be viewed as a >9D array.
2 B G E / B 2 2 2 / / B >CC >C2 >CB >CA >CE >>C >>2 >>B >>A >>E >2C >22 thus, for the first printf statement a, :a, ::a give address of first element . since the indirection :::a gives the value. ,ence, the first line of the output. for the second printf a;> increases in the third dimension thus points to value at >>B, :a;> increments in second dimension thus points to >CB, ::a 2G Technical Aptitude Questions ;> increments the first dimension thus points to >C2 and :::a;> first gets the value at first location and then increments it by >. ,ence, the output. BE+ main* + ] int aO P @ ]>C,2C,/C,BC,?C^,=,:pX for*=@CX =R?X =;;+ ] printf*[Wd\ ,:a+X a;;X ^ p @ aX for*=@CX =R?X =;;+ ] printf*[Wd \ ,:p+X p;;X ^ ^ Answer: !ompiler error7 lvalue re.uired. Explanation: 4rror is in line with statement a;;. The 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 non9modifiable lvalue. BK+ main* + ] static int aO P @ ]C,>,2,/,B^X int :pO P @ ]a,a;>,a;2,a;/,a;B^X int ::ptr @ pX ptr;;X printf*[Zn Wd Wd Wd\, ptr9p, :ptr9a, ::ptr+X :ptr;;X printf*[Zn Wd Wd Wd\, ptr9p, :ptr9a, ::ptr+X :;;ptrX printf*[Zn Wd Wd Wd\, ptr9p, :ptr9a, ::ptr+X ;;:ptrX printf*[Zn Wd Wd Wd\, ptr9p, :ptr9a, ::ptr+X ^ Answer: 111 222 333 3** Explanation: 2E Technical Aptitude Questions 0et us consider the array and the two pointers with some address $ C > 2 / B >CC >C2 >CB >CA >CE p >CC >C2 >CB >CA >CE >CCC >CC2 >CCB >CCA >CCE ptr >CCC 2CCC After e5ecution of the instruction ptr;; value in ptr becomes >CC2, if scaling factor for integer is 2 bytes. $ow ptr ) p is value in ptr ) starting location of array p, *>CC2 ) >CCC+ L *scaling factor+ @ >, :ptr ) a @ value at address pointed by ptr ) starting value of array a, >CC2 has a value >C2 so the value is *>C2 ) >CC+L*scaling factor+ @ >, ::ptr is the value stored in the location pointed by the pointer of ptr @ value pointed by value pointed by >CC2 @ value pointed by >C2 @ >. ,ence the output of the firs printf is >, >, >. After e5ecution of :ptr;; increments value of the value in ptr by scaling factor, so it becomes>CCB. ,ence, the outputs for the second printf are ptr ) p @ 2, :ptr ) a @ 2, ::ptr @ 2. After e5ecution of :;;ptr increments value of the value in ptr by scaling factor, so it becomes>CCB. ,ence, the outputs for the third printf are ptr ) p @ /, :ptr ) a @ /, ::ptr @ /. After e5ecution of ;;:ptr 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 >CCA changes from >CA >C >CE,. ,ence, the outputs for the fourth printf are ptr ) p @ >CCA ) >CCC @ /, :ptr ) a @ >CE ) >CC @ B, ::ptr @ B. ?C+ main* + ] char :.X int =X for *=@CX =R/X =;;+ scanf*[Ws\ ,*.;=++X for *=@CX =R/X =;;+ printf*[Wc\ ,:*.;=++X for *=@CX =R/X =;;+ printf*[Ws\ ,*.;=++X ^ Explanation: ,ere we have only one pointer to type char and since we tae input in the same pointer thus we eep writing over in the same location, each time shifting the pointer value by >. Suppose the inputs are #"<S4, T'A!_ and -&'T<A0. Then for the first input suppose the pointer starts at location >CC then the input one is stored as # " < S 4 ZC Fhen the second input is given the pointer is incremented as = value becomes >, so the input is filled in memory starting from >C>. 2K Technical Aptitude Questions # T ' A ! _ ZC The third input starts filling from the location >C2 # T - & ' T < A 0 ZC This is the final value stored . The first printf prints the values at the position ., .;> and .;2 @ # T - The second printf prints three strings starting from locations ., .;>, .;2 i.e #T-&'T<A0, T-&'T<A0 and -&'T<A0.
?>+ main* + ] void :vpX char ch @ 2g3, :cp @ [goofy\X int = @ 2CX vp @ UchX printf*[Wc\, :*char :+vp+X vp @ U=X printf*[Wd\,:*int :+vp+X vp @ cpX printf*[Ws\,*char :+vp ; /+X ^ Answer: g2Cfy Explanation: 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 ne5t statement prints the value stored in vp after type casting it to the proper data type pointer. the output is 2g3. Similarly the output from second printf is 22C3. The third printf statement type casts it to print the string from the B th value hence the output is 2fy3. ?2+ main * + ] static char :sO P @ ][blac\, [white\, [yellow\, [violet\^X char ::ptrO P @ ]s;/, s;2, s;>, s^, :::pX p @ ptrX ::;;pX printf*[Ws\,:99:;;p ; /+X ^ Answer: c Explanation: &n this problem we have an array of char pointers pointing to start of B strings. Then 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 @ s;/. The ne5t statement increment value in p by > , thus now value of p @ s;2. &n the printf statement the e5pression /C Technical Aptitude Questions is evaluated :;;p causes gets value s;> then the pre decrement is e5ecuted and we get s;> ) > @ s . the indirection operator now gets the value from the array of s and adds / to the starting address. The string is printed starting from this position. Thus, the output is 2c3. ?/+ main*+ ] int i, nX char :5 @ [girl\X n @ strlen*5+X :5 @ 5OnPX for*i@CX iRnX ;;i+ ] printf*[WsZn\,5+X 5;;X ^ ^ Answer: *blan space+ irl rl l Explanation: ,ere a string *a pointer to char+ is initialized with a value [girl\. The strlen function returns the length of the string, thus n has a value B. The ne5t statement assigns value at the nth location *2ZC3+ to the first location. $ow the string becomes [ZCirl\ . $ow the printf statement prints the string after each iteration it increments it starting position. 0oop starts from C to B. The first time 5OCP @ 2ZC3 hence it prints nothing and pointer value is incremented. The second time it prints from 5O>P i.e [irl\ and the third time it prints [rl\ and the last time it prints [l\ and the loop terminates. ?B+ int i,=X for*i@CXiR@>CXi;;+ ] =;@?X assert*iR?+X ^ Answer: 'untime error7 Abnormal program termination. assert failed *iR?+, Rfile nameQ,Rline numberQ Explanation: asserts are used during debugging to mae sure that certain conditions are satisfied. &f assertion fails, the program will terminate reporting the same. After debugging use, Yundef $D4(<% /> Technical Aptitude Questions and this will disable all the assertions from the source code. Assertion is a good debugging tool to mae use of.
??+ main*+ ] int i@9>X ;iX printf*Ni @ Wd, ;i @ Wd ZnN,i,;i+X ^ Answer: i @ 9>, ;i @ 9> Explanation: <nary ; is the only dummy operator in !. Fhere9ever it comes you can =ust ignore it =ust because it has no effect in the e5pressions *hence the name dummy operator+. ?A+ Fhat are the files which are automatically opened when a ! file is e5ecuted` Answer: stdin, stdout, stderr *standard input,standard output,standard error+. ?G+ what will be the position of the file marer` a7 fsee*ptr,C,S44_MS4T+X b7 fsee*ptr,C,S44_M!<'+X Answer : a7 The S44_MS4T sets the file position marer to the starting of the file. b7 The S44_M!<' sets the file position marer to the current position of the file. ?E+ main*+ ] char nameO>CP,sO>2PX scanf*N ZNWO8ZNPZNN,s+X ^ ,ow scanf will e5ecute` Answer: 1irst it checs for the leading white space and discards it.Then it matches with a .uotation mar and then it reads all character upto another .uotation mar. ?K+ Fhat is the problem with the following code segment` while **fgets*receiving array,?C,fileMptr++ S@ 4"1+ X Answer & Explanation: fgets returns a pointer. So the correct end of file chec is checing for S@ $<00. /2 Technical Aptitude Questions AC+ main*+ ] main*+X ^ Answer: 'untime error 7 Stac overflow. Explanation: main function calls itself again and again. 4ach time the function is called its return address is stored in the call stac. Since there is no condition to terminate the function call, the call stac overflows at runtime. So it terminates the program and results in an error. A>+ main*+ ] char :cptr,cX void :vptr,vX c@>CX v@CX cptr@UcX vptr@UvX printf*NWcWvN,c,v+X ^ Answer: !ompiler error *at line number B+7 size of v is <nnown. Explanation: Iou can create a variable of type void : but not of type void, since void is an empty type. &n the second line you are creating variable vptr of type void : and v of type void hence an error. A2+ main*+ ] char :str>@NabcdNX char str2OP@NabcdNX printf*NWd Wd WdN,sizeof*str>+,sizeof*str2+,sizeof*NabcdN++X ^ Answer: 2 ? ? Explanation: &n first sizeof, str> is a character pointer so it gives you the size of the pointer variable. &n second sizeof the name str2 indicates the name of the array whose size is ? *including the TZCT termination character+. The third sizeof is similar to the second one. A/+ main*+ ] char notX not@S2X // Technical Aptitude Questions printf*NWdN,not+X ^ Answer: C Explanation: S is a logical operator. &n ! the value C is considered to be the boolean value 1A0S4, and any non9zero value is considered to be the boolean value T'<4. ,ere 2 is a non9zero value so T'<4. ST'<4 is 1A0S4 *C+ so it prints C. AB+ Ydefine 1A0S4 9> Ydefine T'<4 > Ydefine $<00 C main*+ ] if*$<00+ puts*N$<00N+X else if*1A0S4+ puts*NT'<4N+X else puts*N1A0S4N+X ^ Answer: T'<4 Explanation7 The input program to the compiler after processing by the preprocessor is, main*+] if*C+ puts*N$<00N+X else if*9>+ puts*NT'<4N+X else puts*N1A0S4N+X ^ 6reprocessor doesnTt replace the values given inside the double .uotes. The chec by if condition is boolean value false so it goes to else. &n second if 9> is boolean value true hence NT'<4N is printed. A?+ main*+ ] int @>X printf*NWd@@> is NNWsN,,@@>`NT'<4N7N1A0S4N+X ^ Answer: >@@> is T'<4 Explanation: /B Technical Aptitude Questions Fhen two strings are placed together *or separated by white9space+ they are concatenated *this is called as NstringizationN operation+. So the string is as if it is given as NWd@@> is WsN. The conditional operator* `7 + evaluates to NT'<4N. AA+ main*+ ] int yX scanf*NWdN,Uy+X LL input given is 2CCC if* *yWB@@C UU yW>CC S@ C+ VV yW>CC @@ C + printf*NWd is a leap yearN+X else printf*NWd is not a leap yearN+X ^ Answer: 2CCC is a leap year Explanation: An ordinary program to chec if leap year or not. AG+ Ydefine ma5 ? Ydefine int arr>Oma5P main*+ ] typedef char arr2Oma5PX arr> list@]C,>,2,/,B^X arr2 name@NnameNX printf*NWd WsN,listOCP,name+X ^ Answer: !ompiler error *in the line arr> list @ ]C,>,2,/,B^+ Explanation: arr2 is declared of type array of size ? of characters. So it can be used to declare the variable name of the type arr2. (ut it is not the case of arr>. ,ence an error. Rule of Thumb: Ydefines are used for te5tual replacement whereas typedefs are used for declaring new types. AE+ int i@>CX main*+ ] e5tern int iX ] int i@2CX ] const volatile unsigned i@/CX /? Technical Aptitude Questions printf*NWdN,i+X ^ printf*NWdN,i+X ^ printf*NWdN,i+X ^ Answer: /C,2C,>C Explanation: T]T introduces new bloc and thus new scope. &n the innermost bloc i is declared as, const volatile unsigned which is a valid declaration. i is assumed of type int. So printf prints /C. &n the ne5t bloc, i has value 2C and so printf prints 2C. &n the outermost bloc, i is declared as e5tern, so no storage space is allocated for it. After compilation is over the liner resolves it to global variable i *since it is the only variable visible there+. So it prints iTs value as >C. AK+ main*+ ] int :=X ] int i@>CX =@UiX ^ printf*NWdN,:=+X ^ Answer: >C Explanation7 The variable i is a bloc level variable and the visibility is inside that bloc only. (ut the lifetime of i is lifetime of the function so it lives upto the e5it of main function. Since the i is still allocated space, := prints the value stored in i since = points i. GC+ main*+ ] int i@9>X 9iX printf*Ni @ Wd, 9i @ Wd ZnN,i,9i+X ^ Answer: i @ 9>, 9i @ > Explanation: /A Technical Aptitude Questions 9i is e5ecuted and this e5ecution doesnTt affect the value of i. &n printf first you =ust print the value of i. After that the value of the e5pression 9i @ 9*9>+ is printed. G>+ YincludeRstdio.hQ main*+ ] const int i@BX float =X = @ ;;iX printf*NWd WfN, i,;;=+X ^ Answer7 !ompiler error Explanation7 i is a constant. you cannot change the value of constant G2+ YincludeRstdio.hQ main*+ ] int aO2PO2PO2P @ ] ]>C,2,/,B^, ]?,A,G,E^ ^X int :p,:.X p@UaO2PO2PO2PX :.@:::aX printf*NWd..WdN,:p,:.+X ^ Answer: garbagevalue..> Explanation: p@UaO2PO2PO2P you declare only two 2D arrays. but you are trying to access the third 2D*which you are not declared+ it will print garbage values. :.@:::a starting address of a is assigned integer pointer. now . is pointing to starting address of a.if you print :. meAnswer7it will print first element of /D array. G/+ YincludeRstdio.hQ main*+ ] register i@?X char =OP@ NhelloNX printf*NWs WdN,=,i+X ^ Answer: hello ? Explanation7 /G Technical Aptitude Questions if you declare i as register compiler will treat it as ordinary integer and it will tae integer value. i value may be stored either in register or in memory. GB+ main*+ ] int i@?,=@A,zX printf*NWdN,i;;;=+X ^ Answer: >> Explanation: the e5pression i;;;= is treated as *i;; ; =+
GA+ struct aaa] struct aaa :prevX int iX struct aaa :ne5tX ^X main*+ ] struct aaa abc,def,ghi,=lX int 5@>CCX abc.i@CXabc.prev@U=lX abc.ne5t@UdefX def.i@>Xdef.prev@UabcXdef.ne5t@UghiX ghi.i@2Xghi.prev@UdefX ghi.ne5t@U=lX =l.i@/X=l.prev@UghiX=l.ne5t@UabcX 5@abc.ne5t9Qne5t9Qprev9Qne5t9QiX printf*NWdN,5+X ^ Answer: 2 Explanation: above all statements form a double circular lined listX abc.ne5t9Qne5t9Qprev9Qne5t9Qi this one points to NghiN node the value of at particular node is 2. GG+ struct point ] int 5X int yX ^X struct point origin,:ppX main*+ /E Technical Aptitude Questions ] pp@UoriginX printf*Norigin is*WdWd+ZnN,*:pp+.5,*:pp+.y+X printf*Norigin is *WdWd+ZnN,pp9Q5,pp9Qy+X ^ Answer: origin is*C,C+ origin is*C,C+ Explanation7 pp is a pointer to structure. we can access the elements of the structure either with arrow mar or with indirection operator. 'ote: Since structure point is globally declared 5 U y are initialized as zeroes GE+ main*+ ] int i@MlMabc*>C+X printf*NWdZnN,99i+X ^ int MlMabc*int i+ ] return*i;;+X ^ Answer: K Explanation: return*i;;+ it will first return i and then increments. i.e. >C will be returned. GK+ main*+ ] char :pX int :.X long :rX p@.@r@CX p;;X .;;X r;;X printf*NWp...Wp...WpN,p,.,r+X ^ Answer: CCC>...CCC2...CCCB Explanation: ;; operator when applied to pointers increments address according to their corresponding data9types. /K Technical Aptitude Questions EC+ main*+ ] char c@T T,5,convert*z+X getc*c+X if**cQ@TaT+ UU *cR@TzT++ 5@convert*c+X printf*NWcN,5+X ^ convert*z+ ] return z9/2X ^ Answer: !ompiler error Explanation: declaration of convert and format of getc*+ are wrong. E>+ main*int argc, char ::argv+ ] printf*Nenter the characterN+X getchar*+X sum*argvO>P,argvO2P+X ^ sum*num>,num2+ int num>,num2X ] return num>;num2X ^ Answer: !ompiler error. Explanation: argvO>P U argvO2P are strings. They are passed to the function sum without converting it to integer values. E2+ Y include Rstdio.hQ int oneMdOP@]>,2,/^X main*+ ] int :ptrX ptr@oneMdX ptr;@/X printf*NWdN,:ptr+X ^ Answer7 garbage value BC Technical Aptitude Questions Explanation: ptr pointer is pointing to out of the array range of oneMd. E/+ Y includeRstdio.hQ aaa*+ ] printf*NhiN+X ^ bbb*+] printf*NhelloN+X ^ ccc*+] printf*NbyeN+X ^ main*+ ] int *:ptrO/P+*+X ptrOCP@aaaX ptrO>P@bbbX ptrO2P@cccX ptrO2P*+X ^ Answer7 bye Explanation: ptr is array of pointers to functions of return type int.ptrOCP is assigned to address of the function aaa. Similarly ptrO>P and ptrO2P for bbb and ccc respectively. ptrO2P*+ is in effect of writing ccc*+, since ptrO2P points to ccc. E?+ YincludeRstdio.hQ main*+ ] 1&04 :ptrX char iX ptr@fopen*Nzzz.cN,NrN+X while**i@fgetch*ptr++S@4"1+ printf*NWcN,i+X ^ Answer: contents of zzz.c followed by an infinite loop Explanation: The condition is checed against 4"1, it should be checed against $<00. EA+ main*+ ] int i @CX=@CX B> Technical Aptitude Questions if*i UU =;;+ printf*NWd..WdN,i;;,=+X printf*NWd..Wd,i,=+X ^ Answer: C..C Explanation: The value of i is C. Since this information is enough to determine the truth value of the boolean e5pression. So the statement following the if statement is not e5ecuted. The values of i and = remain unchanged and get printed.
EG+ main*+ ] int iX i @ abc*+X printf*NWdN,i+X ^ abc*+ ] MAH @ >CCCX ^ Answer: >CCC Explanation: $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 >CCC so the function returns value >CCC. EE+ int iX main*+] int tX for * t@BXscanf*NWdN,Ui+9tXprintf*NWdZnN,i++ printf*NWd99N,t99+X ^ LL &f the inputs are C,>,2,/ find the oLp Answer: B99C /99> 2992 Explanation: 0et us assume some 5@ scanf*NWdN,Ui+9t the values during e5ecution will be, t i 5 B C 9B B2 Technical Aptitude Questions / > 92 2 2 C
EK+ main*+] int a@ CXint b @ 2CXchar 5 @>Xchar y @>CX if*a,b,5,y+ printf*NhelloN+X ^ Answer: hello Explanation: The comma operator has associativity from left to right. "nly the rightmost value is returned and the other values are evaluated and ignored. Thus the value of last variable y is returned to chec in if. Since it is a non zero value if becomes true so, NhelloN will be printed. KC+ main*+] unsigned int iX for*i@>XiQ92Xi99+ printf*Nc aptitudeN+X ^ Explanation: i is an unsigned integer. &t is compared with a signed value. Since the both types doesnTt match, signed is promoted to unsigned value. The unsigned e.uivalent of 92 is a huge value so condition becomes false and control comes out of the loop. K>+ &n the following pgm add a stmt in the function fun such that the address of TaT gets stored in T=T. main*+] int : =X void fun*int ::+X fun*U=+X ^ void fun*int ::+ ] int a @CX L: add a stmt here:L ^ Answer: : @ Ua Explanation: The argument of the function is a pointer to a pointer.
K2+ Fhat are the following notations of defining functions nown as` i. int abc*int a,float b+ ] B/ Technical Aptitude Questions L: some code :L ^ ii. int abc*a,b+ int aX float bX ] L: some code:L ^ Answer: i. A$S& ! notation ii. _ernighan U 'itche notation K/+ main*+ ] char :pX p@NWdZnNX p;;X p;;X printf*p92,/CC+X ^ Answer: /CC Explanation: The pointer points to W since it is incremented twice and again decremented by 2, it points to TWdZnT and /CC is printed. KB+ main*+] char aO>CCPX aOCP@TaTXaO>PP@TbTXaO2P@TcTXaOBP@TdTX abc*a+X ^ abc*char aOP+] a;;X printf*NWcN,:a+X a;;X printf*NWcN,:a+X ^ Explanation: The 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.
K?+ func*a,b+ int a,bX ] return* a@ *a@@b+ +X ^ main*+ BB Technical Aptitude Questions ] int process*+,func*+X printf*NThe value of process is Wd SZn N,process*func,/,A++X ^ process*pf,val>,val2+ int *:pf+ *+X int val>,val2X ] return**:pf+ *val>,val2++X ^ Answer: The value if process is C S Explanation: The function TprocessT has / parameters 9 >, a pointer to another function 2 and /, integers. Fhen this function is invoed from main, the following substitutions for formal parameters tae place7 func for pf, / for val> and A for val2. This function returns the result of the operation performed by the function TfuncT. The function func has two integer parameters. The formal parameters are substituted as / for a and A for b. since / is not e.ual to A, a@@b returns C. therefore the function returns C which in turn is returned by the function TprocessT. KA+ void main*+ ] static int i@?X if*99i+] main*+X printf*NWd N,i+X ^ ^ Answer: C C C C Explanation: The variable N&N is declared as static, hence memory for & will be allocated for only once, as it encounters the statement. The function main*+ will be called recursively unless & becomes e.ual to C, and since main*+ is recursively called, so the value of static & ie., C will be printed every time the control is returned. KG+ void main*+ ] int @ret*sizeof*float++X printf*NZn here value is WdN,;;+X ^ int ret*int ret+ ] ret ;@ 2.?X B? Technical Aptitude Questions return*ret+X ^ Answer: ,ere value is G Explanation: The int ret*int ret+, ie., the function name and the argument name can be the same. 1irstly, the function ret*+ is called in which the sizeof*float+ ie., B is passed, after the first e5pression the value in ret will be A, as ret is integer hence the value stored in ret will have implicit type conversion from float to int. The ret is returned in main*+ it is printed after and preincrement.
KE+ void main*+ ] char aOP@N>2/B?ZCNX int i@strlen*a+X printf*Nhere in / WdZnN,;;i+X ^ Answer: here in / A Explanation: The char array TaT will hold the initialized string, whose length will be counted from C till the null character. ,ence the T&T will hold the value e.ual to ?, after the pre9increment in the printf statement, the A will be printed. KK+ void main*+ ] unsigned giveit@9>X int gotitX printf*NWu N,;;giveit+X printf*NWu ZnN,gotit@99giveit+X ^ Answer: C A??/? Explanation: >CC+ void main*+ ] int iX char aOP@NZCNX if*printf*NWsZnN,a++ printf*N" here ZnN+X else printf*N1orget itZnN+X ^ Answer: BA Technical Aptitude Questions " here Explanation: 6rintf will return how many characters does it print. ,ence printing a null character returns > which maes the if statement true, thus N" hereN is printed.
>C>+ void main*+ ] void :vX int integer@2X int :i@UintegerX v@iX printf*NWdN,*int:+:v+X ^ Answer: !ompiler 4rror. Fe cannot apply indirection on type void:. Explanation: -oid pointer is a generic pointer type. $o pointer arithmetic can be done on it. -oid pointers are normally used for, >. 6assing generic pointers to functions and returning such pointers. 2. As a intermediate pointer type. /. <sed when the e5act pointer type will be nown at a later point of time. >C2+ void main*+ ] int i@i;;,=@=;;,@;;X printf*[WdWdWd\,i,=,+X ^ Answer: %arbage values. Explanation: 6n identifier is availa.le to use in program code from the point of its declaration. So e5pressions such as i @ i;; are valid statements. The i, = and are automatic variables and so they contain some garbage value. =ar.age in is gar.age out 2=+=E4. >C/+ void main*+ ] static int i@i;;, =@=;;, @;;X printf*[i @ Wd = @ Wd @ Wd\, i, =, +X ^ Answer: i @ > = @ > @ > BG Technical Aptitude Questions Explanation: Since static variables are initialized to zero by default. >CB+ void main*+ ] while*>+] if*printf*NWdN,printf*NWdN+++ breaX else continueX ^ ^ Answer: %arbage values Explanation: The inner printf e5ecutes first to print some garbage value. The printf returns no of characters printed and this value also cannot be predicted. Still the outer printf prints something and so returns a non9zero value. So it encounters the brea statement and comes out of the while statement. >CB+ main*+ ] unsigned int i@>CX while*i99Q@C+ printf*NWu N,i+X ^ Answer: >C K E G A ? B / 2 > C A??/? A??/BJ.. Explanation: Since i is an unsigned integer it can never become negative. So the e5pression i99 Q@C will always be true, leading to an infinite loop. >C?+ YincludeRconio.hQ main*+ ] int 5,y@2,z,aX if*5@yW2+ z@2X a@2X printf*NWd Wd N,z,5+X ^ Answer: %arbage9value C Explanation: The value of yW2 is C. This value is assigned to 5. The condition reduces to if *5+ or in other words if*C+ and so z goes uninitialized. BE Technical Aptitude Questions Thu! "ule: ,hec all control paths to write bug free code. >CA+ main*+ ] int aO>CPX printf*NWdN,:a;>9:a;/+X ^ Answer: B Explanation: :a and 9:a cancels out. The result is as simple as > ; / @ B S >CG+ Ydefine prod*a,b+ a:b main*+ ] int 5@/,y@BX printf*NWdN,prod*5;2,y9>++X ^ Answer: >C Explanation: The macro e5pands and evaluates to as7 5;2:y9> @Q 5;*2:y+9> @Q >C >CE+ main*+ ] unsigned int i@A?CCCX while*i;;S@C+X printf*NWdN,i+X ^ Answer: > Explanation: $ote the semicolon after the while statement. Fhen the value of i becomes C it comes out of while loop. Due to post9increment on i the value of i while printing is >.
>CK+ main*+ ] int i@CX while*;*;i99+S@C+ i9@i;;X printf*NWdN,i+X ^ Answer: 9> BK Technical Aptitude Questions Explanation: Qnary 8 is the only dummy operator in ,. So it has no effect on the e5pression and now the while loop is, while*i99S@C+ which is false and so breas out of while loop. The value )> is printed due to the post9 decrement operator.
>>/+ main*+ ] float f@?,g@>CX enum]i@>C,=@2C,@?C^X printf*NWdZnN,;;+X printf*NWfZnN,fRR2+X printf*NWlfZnN,fWg+X printf*NWlfZnN,fmod*f,g++X ^ Answer: 0ine no ?7 4rror7 0value re.uired 0ine no A7 !annot apply leftshift to float 0ine no G7 !annot apply mod to float Explanation: 4numeration constants cannot be modified, so you cannot apply ;;. (it9wise 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. >>C+ main*+ ] int i@>CX void pascal f*int,int,int+X f*i;;,i;;,i;;+X printf*N WdN,i+X ^ void pascal f*integer 7i,integer7=,integer 7+ ] write*i,=,+X ^ Answer: !ompiler error7 unnown type integer !ompiler error7 undeclared function write Explanation: 6ascal eyword doesn3t mean that pascal code can be used. &t means that the function follows 6ascal argument passing mechanism in calling the functions. >>>+ void pascal f*int i,int =,int + ] printf*[Wd Wd Wd\,i, =, +X ^ ?C Technical Aptitude Questions void cdecl f*int i,int =,int + ] printf*[Wd Wd Wd\,i, =, +X ^ main*+ ] int i@>CX f*i;;,i;;,i;;+X printf*N WdZnN,i+X i@>CX f*i;;,i;;,i;;+X printf*N WdN,i+X ^ Answer: >C >> >2 >/ >2 >> >C >/ Explanation: 6ascal argument passing mechanism forces the arguments to be called from left to right. cdecl is the normal ! argument passing mechanism where the arguments are passed from right to left.
>>2+. Fhat is the output of the program given below main*+ ] signed char i@CX for*XiQ@CXi;;+ X printf*NWdZnN,i+X ^ Answer 9>2E Explanation $otice the semicolon at the end of the for loop. T,e initial value of the i is set to C. The inner loop e5ecutes to increment the value from C to >2G *the positive range of char+ and then it rotates to the negative value of 9>2E. The condition in the for loop fails and so comes out of the for loop. &t prints the current value of i that is 9>2E.
>>/+ main*+ ] unsigned char i@CX for*XiQ@CXi;;+ X printf*NWdZnN,i+X ^ Answer ?> Technical Aptitude Questions infinite loop Explanation The difference between the previous .uestion and this one is that the char is declared to be unsigned. So the i;; can never yield negative value and iQ@C never becomes false so that it can come out of the for loop. >>B+ main*+ ] char i@CX for*XiQ@CXi;;+ X printf*NWdZnN,i+X
^ Answer: (ehavior is implementation dependent. Explanation: The detail if the char is signedLunsigned by default is implementation dependent. &f the implementation treats the char to be signed by default the program will print )>2E and terminate. "n the other hand if it considers char to be unsigned by default, it goes to infinite loop. Rule: Iou can write programs that have implementation dependent behavior. (ut dont write programs that depend on such behavior. >>?+ &s the following statement a declarationLdefinition. 1ind what does it mean` int *:5+O>CPX Answer Definition. 5 is a pointer to array of*size >C+ integers. Apply cloc9wise rule to find the meaning of this definition. >>A+. Fhat is the output for the program given below typedef enum errorType]warning, error, e5ception,^errorX main*+ ] error g>X g>@>X printf*NWdN,g>+X ^ Answer !ompiler error7 #ultiple declaration for error Explanation ?2 Technical Aptitude Questions The name error is used in the two meanings. "ne means that it is a enumerator constant with value >. The another use is that it is a type name *due to typedef+ for enum errorType. %iven a situation the compiler cannot distinguish the meaning of error to now in what sense the error is used7 error g>X g>@errorX LL which error it refers in each case` Fhen the compiler can distinguish between usages then it will not issue error *in pure technical terms, names can only be overloaded in different namespaces+. Note7 the e5tra comma in the declaration, enum errorType]warning, error, e5ception,^ is not an error. An e5tra comma is valid and is provided =ust for programmer3s convenience.
>>G+ typedef struct error]int warning, error, e5ceptionX^errorX main*+ ] error g>X g>.error @>X printf*NWdN,g>.error+X ^ Answer > Explanation The three usages of name errors can be distinguishable by the compiler at any instance, so valid *they are in different namespaces+. Typedef struct error]int warning, error, e5ceptionX^errorX This error can be used only by preceding the error by struct ayword as in7 struct error some4rrorX typedef struct error]int warning, error, e5ceptionX^errorX This can be used only after . *dot+ or 9Q *arrow+ operator preceded by the variable name as in 7 g>.error @>X printf*NWdN,g>.error+X typedef struct error]int warning, error, e5ceptionX^errorX This can be used to define variables without using the preceding struct eyword as in7 error g>X Since the compiler can perfectly distinguish between these three usages, it is perfectly legal and valid. 'ote ?/ Technical Aptitude Questions This code is given here to =ust e5plain the concept behind. &n real programming don3t use such overloading of names. &t reduces the readability of the code. 6ossible doesn3t mean that we should use itS
>>E+ Yifdef something int some@CX Yendif main*+ ] int thing @ CX printf*NWd WdZnN, some ,thing+X ^ Answer: !ompiler error 7 undefined symbol some Explanation: This is a very simple e5ample for conditional compilation. The name something is not already nown to the compiler maing the declaration int some @ CX effectively removed from the source code. >>K+ Yif something @@ C int some@CX Yendif main*+ ] int thing @ CX printf*NWd WdZnN, some ,thing+X ^ Answer C C Explanation This code is to show that preprocessor e5pressions are not the same as the ordinary e5pressions. &f a name is not nown the preprocessor treats it to be e.ual to zero. >2C+. Fhat is the output for the following program main*+ ] int arr2DO/PO/PX printf*NWdZnN, **arr2D@@: arr2D+UU*: arr2D @@ arr2DOCP++ +X ?B Technical Aptitude Questions ^ Answer > Explanation This is due to the close relation between the arrays and pointers. $ dimensional arrays are made up of *$9>+ dimensional arrays. arr2D is made up of a / single arrays that contains / integers each . The name arr2D refers to the beginning of all the / arrays. :arr2D refers to the start of the first >D array *of / integers+ that is the same address as arr2D. So the e5pression *arr2D @@ :arr2D+ is true *>+. Similarly, :arr2D is nothing but :*arr2D ; C+, adding a zero doesn3t change the valueLmeaning. Again arr2DOCP is the another way of telling :*arr2D ; C+. So the e5pression *:*arr2D ; C+ @@ arr2DOCP+ is true *>+. Since both parts of the e5pression evaluates to true the result is true*>+ and the same is printed. >2>+ void main*+ ] if*aC @@ *unsigned int+9>+ printf*[Iou can answer this if you now how values are represented in memory\+X ^ Answer Iou can answer this if you now how values are represented in memory 45planation a *tilde operator or bit9wise negation operator+ operates on C to produce all ones to fill the space for an integer. )> is represented in unsigned value as all >3s and so both are e.ual. >22+ int swap*int :a,int :b+ ] :a@:a;:bX:b@:a9:bX:a@:a9:bX ^ main*+ ?? arr2D arr2DO>P arr2DO2P arr2DO/P Technical Aptitude Questions ] int 5@>C,y@2CX swap*U5,Uy+X printf*N5@ Wd y @ WdZnN,5,y+X ^ Answer 5 @ 2C y @ >C 45planation This is one way of swapping two values. Simple checing will help understand this. >2/+ main*+ ] char :p @ [ay.m\X printf*[Wc\,;;:*p;;++X ^ Answer7 b >2B+ main*+ ] int i@?X printf*NWdN,;;i;;+X ^ Answer: !ompiler error7 0value re.uired in function main Explanation: ;;i yields an rvalue. 1or postfi5 ;; to operate an lvalue is re.uired. >2?+ main*+ ] char :p @ [ay.m\X char cX c @ ;;:p;;X printf*[Wc\,c+X ^ Answer: b Explanation: There is no difference between the e5pression ;;:*p;;+ and ; ;:p;;. 6arenthesis =ust wors as a visual clue for the reader to see which e5pression is first evaluated. >2A+ int aaa*+ ]printf*[,i\+X^ ?A Technical Aptitude Questions int bbb*+]printf*[hello\+X^ iny ccc*+]printf*[bye\+X^ main*+ ] int * : ptrO/P+ *+X ptrOCP @ aaaX ptrO>P @ bbbX ptrO2P @cccX ptrO2P*+X ^ Answer7 b%e 45planation7 int *: ptrO/P+*+ says that ptr is an array of pointers to functions that taes no arguments and returns the type int. (y the assignment ptrOCP @ 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 ptrO2P contains the address of the function ccc, the call to the function ptrO2P*+ is same as calling ccc*+. So it results in printing NbyeN. >2G+ main*+ ] int i@?X printf*[Wd\,i@;;i @@A+X ^ Answer: 1 Explanation: The e5pression can be treated as i @ *;;i@@A+, because @@ is of higher precedence than @ operator. &n the inner e5pression, ;;i is e.ual to A yielding true*>+. ,ence the result. >2E+ main*+ ] char pO P@NWdZnNX pO>P @ TcTX printf*p,A?+X ^ Answer: A Explanation: ?G Technical Aptitude Questions Due to the assignment pO>P @ 2c3 the string becomes, [WcZn\. Since this string becomes the format string for printf and AS!&& value of A? is 2A3, the same gets printed.
>2K+ void * : abc* int, void * :def+ *+ + + *+X Answer77 abc is a ptr to a function which taes 2 parameters .*a+. an integer variable.*b+. a ptrto a funtion which returns void. the return type of the function is void. Explanation: Apply the cloc9wise rule to find the result. >/C+ main*+ ] while *strcmp*[some\,\someZC\++ printf*[Strings are not e.ualZn\+X ^ Answer: $o output Explanation: 4nding the string constant with ZC e5plicitly maes no difference. So [some\ and [someZC\ are e.uivalent. So, strcmp returns C *false+ hence breaing out of the while loop. >/>+ main*+ ] char str>OP @ ]2s3,3o3,3m3,3e3^X char str2OP @ ]2s3,3o3,3m3,3e3,3ZC3^X while *strcmp*str>,str2++ printf*[Strings are not e.ualZn\+X ^ Answer: [Strings are not e.ual\ [Strings are not e.ual\ J. Explanation: &f a string constant is initialized e5plicitly with characters, 2ZC3 is not appended automatically to the string. Since str> doesn3t have null termination, it treats whatever the values that are in the following positions as part of the string until it randomly reaches a 2ZC3. So str> and str2 are not the same, hence the result.
>/2+ main*+ ] ?E Technical Aptitude Questions int i @ /X for *Xi;;@CX+ printf*[Wd\,i+X ^ Answer: !ompiler 4rror7 0value re.uired. Explanation: As we now that increment operators return rvalues and hence it cannot appear on the left hand side of an assignment operation.
>//+ void main*+ ] int :mptr, :cptrX mptr @ *int:+malloc*sizeof*int++X printf*[Wd\,:mptr+X int :cptr @ *int:+calloc*sizeof*int+,>+X printf*[Wd\,:cptr+X ^ Answer: garbage9value C Explanation: The memory space allocated by malloc is uninitialized, whereas calloc returns the allocated memory space initialized to zeros. >/B+ void main*+ ] static int iX while*iR@>C+ *iQ2+`i;;7i99X printf*[Wd\, i+X ^ Answer: /2GAG Explanation: Since i is static it is initialized to C. &nside the while loop the conditional operator evaluates to false, e5ecuting i99. This continues till the integer value rotates to positive value */2GAG+. The while condition becomes false and hence, comes out of the while loop, printing the i value. >/?+ main*+ ] int i@>C,=@2CX = @ i, =`*i,=+`i7=7=X printf*NWd WdN,i,=+X ^ ?K Technical Aptitude Questions Answer: >C >C Explanation: The Ternary operator * ` 7 + is e.uivalent for if9then9else statement. So the .uestion can be written as7 if*i,=+ ] if*i,=+ = @ iX else = @ =X ^ else = @ =X >/A+ >. const char :aX 2. char: const aX /. char const :aX 9Differentiate the above declarations. Answer: >. TconstT applies to char : rather than TaT * pointer to a constant char + :a@T1T 7 illegal a@N,iN 7 legal 2. TconstT applies to TaT rather than to the value of a *constant pointer to char + :a@T1T 7 legal a@N,iN 7 illegal /. Same as >. >/G+ main*+ ] int i@?,=@>CX i@iU@=UU>CX printf*NWd WdN,i,=+X ^ Answer: > >C Explanation: The e5pression can be written as i@*iU@*=UU>C++X The inner e5pression *=UU>C+ evaluates to > because =@@>C. i is ?. i @ ?U> is >. ,ence the result. AC Technical Aptitude Questions >/E+ main*+ ] int i@B,=@GX = @ = VV i;; UU printf*NI"< !A$N+X printf*NWd WdN, i, =+X ^ Answer: B > Explanation: 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 e5pression3s truth value is >. (ecause it is followed by VV and true SS 2anything4 IV true where 2anything4 will not .e evaluated. So the remaining e5pression is not evaluated and so the value of i remains the same. Similarly when UU operator is involved in an e5pression, when any of the operands become false, the whole e5pression3s truth value becomes false and hence the remaining e5pression will not be evaluated. false (( 2anything4 IV false where 2anything4 will not .e evaluated. >/K+ main*+ ] register int a@2X printf*NAddress of a @ WdN,Ua+X printf*N-alue of a @ WdN,a+X ^ Answer: !ompier 4rror7 TUT on register variable "ule to "ee!er: & #a$$ress o% & operator 'annot !e applie$ on re(ister )aria!les* >BC+ main*+ ] float i@>.?X switch*i+ ] case >7 printf*N>N+X case 27 printf*N2N+X default 7 printf*NCN+X ^ ^ Answer: !ompiler 4rror7 switch e5pression not integral Explanation: A> Technical Aptitude Questions $witch statements can .e applied only to integral types. >B>+ main*+ ] e5tern iX printf*NWdZnN,i+X ] int i@2CX printf*NWdZnN,i+X ^ ^ Answer: 0iner 4rror 7 <nresolved e5ternal symbol i Explanation: The identifier i is available in the inner bloc and so using e5tern has no use in resolving it. >B2+ main*+ ] int a@2,:f>,:f2X f>@f2@UaX :f2;@:f2;@a;@2.?X printf*NZnWd Wd WdN,a,:f>,:f2+X ^ Answer: >A >A >A Explanation: f> and f2 both refer to the same memory location a. So changes through f> and f2 ultimately affects only the value of a. >B/+ main*+ ] char :p@N%""DNX char aO P@N%""DNX printf*NZn sizeof*p+ @ Wd, sizeof*:p+ @ Wd, strlen*p+ @ WdN, sizeof*p+, sizeof*:p+, strlen*p++X printf*NZn sizeof*a+ @ Wd, strlen*a+ @ WdN, sizeof*a+, strlen*a++X ^ Answer: sizeof*p+ @ 2, sizeof*:p+ @ >, strlen*p+ @ B sizeof*a+ @ ?, strlen*a+ @ B Explanation: sizeof*p+ @Q sizeof*char:+ @Q 2 sizeof*:p+ @Q sizeof*char+ @Q > Similarly, sizeof*a+ @Q size of the character array @Q ? A2 Technical Aptitude Questions 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 $<00 character should also be taen into account. >BB+ Ydefine D&#* array, type+ sizeof*array+Lsizeof*type+ main*+ ] int arrO>CPX printf*[The dimension of the array is Wd\, D&#*arr, int++X ^ Answer: >C Explanation: The size of integer array of >C elements is >C : sizeof*int+. The macro e5pands to sizeof*arr+Lsizeof*int+ @Q >C : sizeof*int+ L sizeof*int+ @Q >C. >B?+ int D&#*int arrayOP+ ] return sizeof*array+Lsizeof*int +X ^ main*+ ] int arrO>CPX printf*[The dimension of the array is Wd\, D&#*arr++X ^ Answer: > Explanation: 6rrays cannot .e passed to functions as arguments and only the pointers can .e passed. So the argument is e.uivalent to int : array *this is one of the very few places where OP and : usage are e.uivalent+. The return statement becomes, sizeof*int :+L sizeof*int+ that happens to be e.ual in this case. >BA+ main*+ ] static int aO/PO/P@]>,2,/,B,?,A,G,E,K^X int i,=X static :pOP@]a,a;>,a;2^X for*i@CXiR/Xi;;+ ] for*=@CX=R/X=;;+ printf*NWdZtWdZtWdZtWdZnN,:*:*p;i+;=+, A/ Technical Aptitude Questions :*:*=;p+;i+,:*:*i;p+;=+,:*:*p;=+;i++X ^ ^ Answer: > > > > 2 B 2 B / G / G B 2 B 2 ? ? ? ? A E A E G / G / E A E A K K K K Explanation: :*:*p;i+;=+ is e.uivalent to pOiPO=P. >BG+ main*+ ] void swap*+X int 5@>C,y@EX swap*U5,Uy+X printf*N5@Wd y@WdN,5,y+X ^ void swap*int :a, int :b+ ] :a 8@ :b, :b 8@ :a, :a 8@ :bX ^ Answer: 5@>C y@E Explanation: <sing 8 lie 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 tae any number of arguments *not no arguments+ and returns nothing. So this doesn3t issue a compiler error by the call swap*U5,Uy+X that has two arguments. This convention is historically due to pre9A$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 :a, int :b ] :a 8@ :b, :b 8@ :a, :a 8@ :bX ^ AB Technical Aptitude Questions where the arguments follow the *+. So naturally the declaration for swap will loo lie, void swap*+ which means the swap can tae any number of arguments. >BE+ main*+ ] int i @ 2?GX int :i6tr @ UiX printf*NWd WdN, :**char:+i6tr+, :**char:+i6tr;>+ +X ^ Answer: > > Explanation: The integer value 2?G is stored in the memory as, CCCCCCC> CCCCCCC>, so the individual bytes are taen by casting it to char : and get printed. >BK+ main*+ ] int i @ 2?EX int :i6tr @ UiX printf*NWd WdN, :**char:+i6tr+, :**char:+i6tr;>+ +X ^ Answer: 2 > Explanation: The integer value 2?G can be represented in binary as, CCCCCCC> CCCCCCC>. 'emember that the &$T40 machines are 2small9endian3 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. The integer value 2?E is stored in memory as7 CCCCCCC> CCCCCC>C. >?C+ main*+ ] int i@/CCX char :ptr @ UiX :;;ptr@2X printf*NWdN,i+X ^ Answer: ??A Explanation: The integer value /CC in binary notation is7 CCCCCCC> CC>C>>CC. &t is stored in memory *small9endian+ as7 CC>C>>CC CCCCCCC>. 'esult of the e5pression :;;ptr @ 2 maes the memory representation as7 CC>C>>CC A? Technical Aptitude Questions CCCCCC>C. So the integer corresponding to it is CCCCCC>C CC>C>>CC @Q ??A. >?>+ Yinclude Rstdio.hQ main*+ ] char : str @ NhelloNX char : ptr @ strX char least @ >2GX while *:ptr;;+ least @ *:ptrRleast + `:ptr 7leastX printf*NWdN,least+X ^ Answer: C Explanation: After 2ptr3 reaches the end of the string the value pointed by 2str3 is 2ZC3. So the value of 2str3 is less than that of 2least3. So the value of 2least3 finally is C. >?2+ Declare an array of $ pointers to functions returning pointers to functions returning pointers to characters` Answer: *char:*:+* ++ *:ptrO$P+* +X >?/+ main*+ ] struct student ] char nameO/CPX 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 ^ Answer: !ompiler 4rror7 <ndefined structure date Explanation: &nside the struct definition of 2student3 the member of type struct date is given. The compiler doesn3t have the definition of date structure *forward reference is not allowed in ! in this case+ so it issues an error. AA Technical Aptitude Questions >?B+ main*+ ] struct dateX struct student ] char nameO/CPX 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 ^ Answer: !ompiler 4rror7 <ndefined structure date Explanation: "nly declaration of struct date is available inside the structure definition of 2student3 but to have a variable of type struct date the definition of the structure is re.uired. >??+ There were >C records stored in [somefile.dat\ but the following program printed >> names. Fhat went wrong` void main*+ ] struct student ] char nameO/CP, rollnoOAPX ^studX 1&04 :fp @ fopen*[somefile.dat\,\r\+X while*Sfeof*fp++ ] fread*Ustud, sizeof*stud+, > , fp+X puts*stud.name+X ^ ^ Explanation: fread reads >C records and prints the names successfully. &t will return 4"1 only when fread tries to read another record and fails reading 4"1 *and returning 4"1+. So it prints the last record again. After this only the condition feof*fp+ becomes false, hence comes out of the while loop. >?A+ &s there any difference between the two declarations, >. int foo*int :arrOP+ and AG Technical Aptitude Questions 2. int foo*int :arrO2P+ Answer: $o Explanation: 1unctions can only pass pointers and not arrays. The numbers that are allowed inside the OP is =ust for more readability. So there is no difference between the two declarations. >?G+ Fhat is the subtle error in the following code segment` void fun*int n, int arrOP+ ] int :p@CX int i@CX while*i;;Rn+ p @ UarrOiPX :p @ CX ^ Answer & Explanation: &f the body of the loop never e5ecutes p is assigned no address. So p remains $<00 where :p @C may result in problem *may rise to runtime error [$<00 pointer assignment\ and terminate the program+. >?E+ Fhat is wrong with the following code` int :foo*+ ] int :s @ malloc*sizeof*int+>CC+X assert*s S@ $<00+X return sX ^ Answer & Explanation: assert macro should be used for debugging and finding out bugs. The chec s S@ $<00 is for errorLe5ception handling and for that assert shouldn3t be used. A plain if and the corresponding remedy statement has to be given. >?K+ Fhat is the hidden bug with the following statement` assert*val;; S@ C+X Answer & Explanation: Assert macro is used for debugging and removed in release version. &n assert, the e5perssion involves side9effects. So the behavior of the code becomes different in case of debug version and the release version thus leading to a subtle bug. "ule to "ee!er: !onFt use expressions that have side3effects in assert statements. AE Technical Aptitude Questions >AC+ void main*+ ] int :i @ C5BCCX LL i points to the address BCC :i @ CX LL set the value of memory location pointed by iX ^ Answer: <ndefined behavior Explanation: The 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. >A>+ Ydefine assert*cond+ if*S*cond++ Z *fprintf*stderr, Nassertion failed7 Ws, file Ws, line Wd ZnN,Ycond,Z MM1&04MM,MM0&$4MM+, abort*++ void main*+ ] int i @ >CX if*i@@C+ assert*i R >CC+X else printf*NThis statement becomes else for if in assert macroN+X ^ Answer7 $o output Explanation: The else part in which the printf is there becomes the else for if in the assert macro. ,ence nothing is printed. The solution is to use conditional operator instead of if statement, Ydefine assert*cond+ **cond+`*C+7 *fprintf *stderr, Nassertion failed7 Z Ws, file Ws, line Wd ZnN,Ycond, MM1&04MM,MM0&$4MM+, abort*+++ $ote7 ,owever this problem of [matching with nearest else\ cannot be solved by the usual method of placing the if statement inside a bloc lie this, Ydefine assert*cond+ ] Z if*S*cond++ Z *fprintf*stderr, Nassertion failed7 Ws, file Ws, line Wd ZnN,Ycond,Z MM1&04MM,MM0&$4MM+, abort*++ Z ^ >A2+ &s the following code legal` struct a AK Technical Aptitude Questions ] int 5X struct a bX ^ Answer7 $o Explanation: &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. >A/+ &s the following code legal` struct a ] int 5X struct a :bX ^ Answer: Ies. Explanation: :b is a pointer to type struct a and so is legal. The compiler nows, the size of the pointer to a structure even before the size of the structure is determined*as you now the pointer to any type is of same size+. This type of structures is nown as 2self9referencing3 structure. >AB+ &s the following code legal` typedef struct a ] int 5X aType :bX ^aType Answer: $o Explanation: The typename aType is not nown at the point of declaring the structure *forward references are not made for typedefs+. >A?+ &s the following code legal` typedef struct a aTypeX struct a ] int 5X aType :bX ^X Answer: Ies GC Technical Aptitude Questions Explanation: The typename aType is nown at the point of declaring the structure, because it is already typedefined. >AA+ &s the following code legal` void main*+ ] typedef struct a aTypeX aType some-ariableX struct a ] int 5X aType :bX ^X ^ Answer: $o Explanation: Fhen the declaration, typedef struct a aTypeX is encountered body of struct a is not nown. This is nown as 2incomplete types3.
>AG+ void main*+ ] printf*[sizeof *void :+ @ Wd Zn[, sizeof* void :++X printf*[sizeof *int :+ @ Wd Zn\, sizeof*int :++X printf*[sizeof *double :+ @ Wd Zn\, sizeof*double :++X printf*[sizeof*struct unnown :+ @ Wd Zn\, sizeof*struct unnown :++X ^ Answer : sizeof *void :+ @ 2 sizeof *int :+ @ 2 sizeof *double :+ @ 2 sizeof*struct unnown :+ @ 2 Explanation: The pointer to any type is of same size. >AE+ char inputStringO>CCP @ ]C^X To get string input from the eyboard which one of the following is better` >+ gets*inputString+ 2+ fgets*inputString, sizeof*inputString+, fp+ Answer & Explanation: The second one is better because gets*inputString+ doesnTt now the size of the string passed and so, if a very big input *here, more than >CC chars+ G> Technical Aptitude Questions the charactes will be written past the input string. Fhen fgets is used with stdin performs the same operation as gets but is safe. >AK+ Fhich version do you prefer of the following two, >+ printf*[Ws\,str+X LL or the more curt one 2+ printf*str+X Answer & Explanation: 6refer the first one. &f the str contains any format characters lie Wd then it will result in a subtle bug. >GC+ void main*+ ] int i@>C, =@2X int :ip@ Ui, :=p @ U=X int @ :ipL:=pX printf*[Wd\,+X ^ Answer: !ompiler 4rror7 [<ne5pected end of file in comment started in line ?\. Explanation: The programmer intended to divide two integers, but by the [ma5imum munch\ rule, the compiler treats the operator se.uence L and : as L: which happens to be the starting of comment. To force what is intended by the programmer, int @ :ipL :=pX LL give space e5plicity separating L and : LLor int @ :ipL*:=p+X LL put braces to force the intention will solve the problem. >G>+ void main*+ ] char chX for*ch@CXchR@>2GXch;;+ printf*[Wc Wd Zn[, ch, ch+X ^ Answer: &mplementaion dependent Explanation: The char type may be signed or unsigned by default. &f it is signed then ch;; is e5ecuted after ch reaches >2G and rotates bac to 9>2E. Thus ch is always smaller than >2G. >G2+ &s this code legal` int :ptrX G2 Technical Aptitude Questions ptr @ *int :+ C5BCCX Answer: Ies Explanation: The pointer ptr will point at the integer in the memory location C5BCC. >G/+ main*+ ] char aOBP@N,400"NX printf*NWsN,a+X ^ Answer: !ompiler error7 Too many initializers Explanation: The array a is of size B but the string constant re.uires A bytes to get stored. >GB+ main*+ ] char aOBP@N,400NX printf*NWsN,a+X ^ Answer: ,400WbSabSb```baaS Explanation: The character array has the memory =ust enough to hold the string [,400\ and doesnt have enough space to store the terminating null character. So it prints the ,400 correctly and continues to print garbage values till it accidentally comes across a $<00 character. >G?+ main*+ ] int a@>C,:=X void :X =@@UaX =;;X ;;X printf*NZn Wu Wu N,=,+X ^ Answer: !ompiler error7 !annot increment a void pointer Explanation: -oid pointers are generic pointers and they can be used only when the type is not nown and as an intermediate address storage type. $o pointer arithmetic can be done on it and you cannot apply indirection operator *:+ on void pointers. G/ Technical Aptitude Questions >GA+ main*+ ] e5tern int iX ] int i@2CX ] const volatile unsigned i@/CX printf*NWdN,i+X ^ printf*NWdN,i+X ^ printf*NWdN,i+X ^ int iX >GG+ 6rintf can be implemented by using MMMMMMMMMM list. Answer: -ariable length argument lists >GE+ char :some1un*+ ] char :temp @ [string constantNX return tempX ^ int main*+ ] puts*some1un*++X ^ Answer7 string constant Explanation7 The program suffers no problem and gives the output correctly because the character constants are stored in codeLdata area and not allocated in stac, so this doesn3t lead to dangling pointers. >GK+ char :some1un>*+ ] char tempO P @ [stringNX return tempX ^ char :some1un2*+ ] char tempO P @ ]2s3, 2t3,3r3,3i3,3n3,3g3^X return tempX ^ int main*+ ] puts*some1un>*++X GB Technical Aptitude Questions puts*some1un2*++X ^ Answer7 %arbage values. Explanation7 (oth the functions suffer from the problem of dangling pointers. &n some1un>*+ temp is a character array and so the space for it is allocated in heap and is initialized with character string [string\. This is created dynamically as the function is called, so is also deleted dynamically on e5iting the function so the string data is not available in the calling function main*+ leading to print some garbage values. The function some1un2*+ also suffers from the same problem but the problem can be easily identified in this case. G?