+ All Categories
Home > Documents > C net apti (gud).doc

C net apti (gud).doc

Date post: 04-Jun-2018
Category:
Upload: venkat-theertha-chowdary
View: 249 times
Download: 0 times
Share this document with a friend

of 32

Transcript
  • 8/14/2019 C net apti (gud).doc

    1/32

    Predict the output or error(s) for the following:

    1. void main(){ int const * p=5; printf("%d",++(*p));}

    Answer:Compiler error: Cannot modify a constant value.Explanation:p is a pointer to a "constant integer". But we tried to change the value of the "constantinteger".

    2. main(){ char s[ ]="man";

    int i; for(i=0;s[ i ];i++) printf(" n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);}

    Answer: mmmm aaaa nnnnExplanation:s i! #$i%s& #$s%i& i s! are all different ways of expressing the same idea. 'enerallyarray name is the (ase address for that array. )ere s is the (ase address. i is the indexnum(er*displacement from the (ase address. +o indirecting it with # is same as s i!. i s!may (e surprising. But in the case of C it is same as s i!.

    !. main(){ f oat m# = 1.1; do$ # &o$ = 1.1; if(m#==&o$)printf("' ov# ");# s# printf("' hat# ");}

    Answer:, hate -

    Explanation:or floating point num(ers $float dou(le long dou(le& the values cannot (e predictedexactly. /epending on the num(er of (ytes the precession with of the valuerepresented varies. loat ta0es 1 (ytes and long dou(le ta0es 23 (ytes. +o float stores3.4 with less precision than long dou(le.5ule of 6hum(:

  • 8/14/2019 C net apti (gud).doc

    2/32

    7ever compare or at8least (e cautious when using floating point num(ers with relationaloperators $99 ; ;9 9 ? 2

    Explanation:@hen static storage class is given it is initiali ed once. 6he change in the value of astatic varia(le is retained even (etween the function calls. ain is also treated li0e anyother ordinary function which can (e called recursively.

    5. main(){ int c[ ]= 2.-,!. , , ./,5 ; int ,*p=c,* =c; for( =0; 5; ++) printf(" %d ",*c); ++ ; for( =0; 5; ++)printf(" %d ",*p);++p; } Answer: ? ? ? ? ? ? > 1 =

    Explanation:,nitially pointer c is assigned to (oth p and D. ,n the first loop since only D isincremented and not c the value ? will (e printed = times. ,n second loop p itself isincremented. +o the values ? > 1 = will (e printed.

    . main(){ #3t#rn int i; i=20;

    printf("%d",i);} Answer:in0er Error : -ndefined sym(ol FGiFExplanation:

    extern storage class in the following declaration extern int iHspecifies to the compiler that the memory for i is allocated in some other program and

  • 8/14/2019 C net apti (gud).doc

    3/32

    that address will (e given to the current program at the time of lin0ing. But lin0er findsthat no other varia(le of name i is availa(le in any other program with memory spaceallocated for it. )ence a lin0er error has occurred .

    /. main(){ int i= 1, = 1,4=0, =2,m; m=i++ ++ 4++66 ++; printf("%d %d %d %d %d",i, ,4, ,m);}

    Answer: 3 3 2 > 2

    Explanation :ogical operations always give a result of 2 or 3 . And also the logical A7/ $II& operator

    has higher priority over the logical J5 $KK& operator. +o the expression Li%% II M%% II0%%N is executed first. 6he result of this expression is 3 $82 II 82 II 3 9 3&. 7ow theexpression is 3 KK ? which evaluates to 2 $(ecause J5 operator always gives 2 except forL3 KK 3N com(ination8 for which it gives 3&. +o the value of m is 2. 6he values of othervaria(les are also incremented (y 2.

    -. main(){ char *p; printf("%d %d ",si7#of(*p),si7#of(p));}

    Answer: 2 ?

    Explanation: 6he si eof$& operator gives the num(er of (ytes ta0en (y its operand. O is a characterpointer which needs one (yte for storing its value $a character&. )ence si eof$#p& givesa value of 2. +ince it needs two (ytes to store the address of the character pointersi eof$p& gives ?.

    8. main(){ int i=!; s9itch(i) d#fa$ t:printf("7#ro"); cas# 1: printf("on#"); r#a4; cas# 2:printf("t9o"); r#a4; cas# !: printf("thr##"); r#a4;

  • 8/14/2019 C net apti (gud).doc

    4/32

    }

    Answer :three

    Explanation :

    6he default case can (e placed anywhere inside the loop. ,t is executed only when allother cases doesnFt match.

    10. main(){ printf("%3", 1 );}

    Answer:fff3

    Explanation :

    82 is internally represented as all 2Fs. @hen left shifted four times the least significant 1(its are filled with 3Fs.6he Px format specifier specifies that the integer value (e printedas a hexadecimal value.

    11. main(){ char strin []="

  • 8/14/2019 C net apti (gud).doc

    5/32

  • 8/14/2019 C net apti (gud).doc

    6/32

  • 8/14/2019 C net apti (gud).doc

    7/32

    ;str$ct && * ;;}

    Answer:

    Compiler Error

    Explanation: 6he structure yy is nested within structure xx. )ence the elements are of yy are to (eaccessed through the instance of structure xx which needs an instance of yy to (e0nown. ,f the instance is created after defining the structure the compiler will not 0nowa(out the instance relative to xx. )ence for nested structure yy you have to declaremem(er.

    18. main(){printf(" na ");

    printf(" si");printf(" rha");}

    Answer:hai

    Explanation:Sn 8 newlineS( 8 (ac0spaceSr 8 linefeed

    20. main(){int i=5;printf("%d%d%d%d%d%d",i++,i ,++i, i,i);}

    Answer:1==1=

    Explanation: 6he arguments in a function call are pushed into the stac0 from left to right. 6heevaluation is (y popping out from the stac0. and the evaluation is from right to lefthence the result.

    21. >d#fin# s $ar#(3) 3*3main(){int i;i = Cs $ar#( );printf("%d",i);}

    http://techpreparation.com/aptitute-questions/c-aptitude-questions3.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions3.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions3.htm
  • 8/14/2019 C net apti (gud).doc

    8/32

    Answer:1

    Explanation:the macro call sDuare$1& will su(stituted (y 1#1 so the expression (ecomes i 9 1*1#1 .+ince * and # has eDual priority the expression will (e evaluated as $ 1*1 i.e. 2 #1 9

    1

    22. main(){char *p="hai fri#nds",*p1;p1=p;9hi #(*p?=B 0B) ++*p++;printf("%s %s",p,p1);}

    Answer:i(Md#fin# a 10main(){>d#fin# a 50printf("%d",a);}

    Answer:=3

    Explanation: 6he preprocessor directives can (e redefined anywhere in the program. +o the mostrecently assigned value will (e ta0en.

    2 . >d#fin# c rscr() 100main(){c rscr();printf("%d n",c rscr());}

    Answer:

    http://techpreparation.com/aptitute-questions/c-aptitude-questions3.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions3.htm
  • 8/14/2019 C net apti (gud).doc

    9/32

    233

    Explanation:Oreprocessor executes as a seperate pass (efore the execution of the compiler. +otextual replacement of clrscr$& to 233 occurs.6he input program to compiler loo0s li0ethis :

    main$& { 233H printf$"PdSn" 233&H } 7ote:233H is an executa(le statement (ut with no action. +o it doesnFt give any pro(lem.

    25. main(){printf("%p",main);}

    Answer: +ome address will (e printed.

    Explanation: unction names are Must addresses $Must li0e array names are addresses&.main$& is also a function. +o the address of function main will (e printed. Pp in printfspecifies that the argument is an address. 6hey are printed as hexadecimal num(ers.

    2 . main(){c rscr();}c rscr(); Answer:7o output*error

    Explanation: 6he first clrscr$& occurs inside a function. +o it (ecomes a function call . ,n the secondclrscr$&H is a function declaration $(ecause it is not inside any function&.

    2/. #n$m co ors DEFGH,DE I,JKIIL main(){

    printf("%d..%d..%d",DEFGH,DE I,JKIIL); r#t$rn(1);

    }

    Answer:3..2..?

    http://techpreparation.com/aptitute-questions/c-aptitude-questions4.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions4.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions4.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions4.htm
  • 8/14/2019 C net apti (gud).doc

    10/32

    Explanation:enum assigns num(ers starting from 3 if not explicitly defined.

    2-. void main(){ char far *farth#r,*farth#st; printf("%d..%d",si7#of(farth#r),si7#of(farth#st));

    Answer:1..?

    Explanation: the second pointer is of char type and not a far pointer

    28. main()

    { int i= 00, =!00; printf("%d..%d");}

    Answer:133..>33

    Explanation:printf ta0es the values of the first two assignments of the program. Any num(er ofprintfFs may (e given. All of them ta0e only the first two values. ,f more num(er ofassignments given in the program then printf will ta0e gar(age values.

    !0. main(){ char *p; p="

  • 8/14/2019 C net apti (gud).doc

    11/32

    printf("%d",i); if (i@2) oto h#r#; i++; }

    f$n(){ h#r#: printf("AA");}

    Answer:Compiler error: -ndefined la(el FhereF in function main

    Explanation:a(els have functions scope in other words 6he scope of the la(els is limited tofunctions . 6he la(el FhereF is availa(le in function fun$& )ence it is not visi(le in functionmain.

    !2. main(){ static char nam#s[5][20]= "pasca ","ada","co o ","fortran"," p#r " ; int i; char *t; t=nam#s[!]; nam#s[!]=nam#s[ ]; nam#s[ ]=t;

    for (i=0;i = ;i++) printf$"Ps" names i!&H}

    Answer:Compiler error: value reDuired in function main

    Explanation:Array names are pointer constants. +o it cannot (e modified.

    !!. void main(){ int i=5; printf("%d",i++ + ++i);}

    Answer:Jutput Cannot (e predicted exactly.

    Explanation:+ide effects are involved in the evaluation of i

    ! . void main(){

    http://techpreparation.com/aptitute-questions/c-aptitude-questions4.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions4.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions4.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions4.htm
  • 8/14/2019 C net apti (gud).doc

    12/32

    int i=5; printf("%d",i+++++i);}

    Answer:Compiler Error

    Explanation: 6he expression i%%%%%i is parsed as i %% %% % i which is an illegal com(ination ofoperators.

    !5. >inc $d#main(){int i=1, =2;s9itch(i) cas# 1: printf("JMMN");

    r#a4; cas# : printf("DFN"); r#a4; }

    Answer:Compiler Error: Constant expression reDuired in function main.

    Explanation: 6he case statement can have only constant expressions $this implies that we cannotuse varia(le names directly so an error&. 7ote:Enumerated types can (e used in case statements.

    ! . main(){int i;printf("%d",scanf("%d", i)); CC va $# 10 is iv#n as inp$t h#r#}

    Answer:2

    Explanation:

    +canf returns num(er of items successfully read and not 2*3. )ere 23 is given as inputwhich should have (een scanned successfully. +o num(er of items read is 2.

    !/. >d#fin# f( , 2) >> 2main(){int var12=100;printf("%d",f(var,12));

  • 8/14/2019 C net apti (gud).doc

    13/32

    Answer:233

    !-. main(){int i=0; for(;i++;printf("%d",i)) ;printf("%d",i);}

    Answer: 2

    Explanation:(efore entering into the for loop the chec0ing condition is "evaluated". )ere it evaluatesto 3 $false& and comes out of the loop and i is incremented $note the semicolon after

    the for loop&.!8. >inc $d#main(){ char s[]= BaB,B B,BcB,B nB,BcB,B 0B ; char *p,*str,*str1; p= s[!]; str=p; str1=s; printf("%d",++*p + ++*str1 !2);}

    Answer:

    Explanation:p is pointing to character FSnF.str2 is pointing to character FaF %%#p meAnswer:"p ispointing to FSnF and that is incremented (y one." the A+C,, value of FSnF is 23. then it isincremented to 22. the value of %%#p is 22. %%#str2 meAnswer:"str2 is pointing to FaFthat is incremented (y 2 and it (ecomes F(F. A+C,, value of F(F is 4T. (oth 22 and 4T isadded and result is su(tracted from >?.i.e. $22%4T8>?&9RR$" "&H

    0. >inc $d#

    main(){ str$ct 33 int 3=!; char nam#[]="h# o"; ;str$ct 33 *s=ma oc(si7#of(str$ct 33));printf("%d",s @3);

    http://techpreparation.com/aptitute-questions/c-aptitude-questions5.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions5.htm
  • 8/14/2019 C net apti (gud).doc

    14/32

    printf("%s",s @nam#);}

    Answer:Compiler Error

    Explanation:,nitiali ation should not (e done for structure mem(ers inside the structure declaration

    1. >inc $d#main(){str$ct 33 int 3; str$ct && char s;

    str$ct 33 *p; ; str$ct && * ; ;

    Answer:Compiler Error

    Explanation:in the end of nested structure yy a mem(er have to (e declared

    2. main(){ #3t#rn int i; i=20; printf("%d",si7#of(i));}

    Answer:in0er error: undefined sym(ol FGiF.

    Explanation:extern declaration specifies that the varia(le i is defined somewhere else. 6he compilerpasses the external varia(le to (e resolved (y the lin0er. +o compiler doesnFt find an

    error. /uring lin0ing the lin0er searches for the definition of i. +ince it is not found thelin0er flags an error.

    !. main(){printf("%d", o$t);}

    int out9233H

    http://techpreparation.com/aptitute-questions/c-aptitude-questions5.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions5.htm
  • 8/14/2019 C net apti (gud).doc

    15/32

    Answer:Compiler error: undefined sym(ol out in function main.

    Explanation: 6he rule is that a varia(le is availa(le for use from the point of declaration. Even thougha is a glo(al varia(le it is not availa(le for main. )ence an error.

    . main(){ #3t#rn o$t; printf("%d", o$t);} int o$t=100;

    Answer:233

    Explanation:

    6his is the correct way of writing the previous program.5. main(){ sho9();}void sho9(){ printf("'Bm th# r#at#st");}

    Answer:Compier error: 6ype mismatch in redeclaration of show.

    Explanation:@hen the compiler sees the function show it doesnFt 0now anything a(out it. +o thedefault return type $ie int& is assumed. But when compiler sees the actual definition ofshow mismatch occurs since it is declared as void. )ence the error.

    6he solutions are as follows:2. declare void show$& in main$& .?. define show$& (efore main$&.>. declare extern void show$& (efore the use of show$&.

    . main( ){

    int a[2][!][2] = 2, , /,- , !, , 2,2 , 2,! , !, ; printf(O%$ %$ %$ %d nP,a,*a,**a,***a); printf(O%$ %$ %$ %d nP,a+1,*a+1,**a+1,***a+1);

    Answer:233 233 233 ?221 231 23? >

    http://techpreparation.com/aptitute-questions/c-aptitude-questions5.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions6.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions5.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions6.htm
  • 8/14/2019 C net apti (gud).doc

    16/32

    /. main( ){ int a[ ] = 10,20,!0, 0,50 , ,*p; for( =0; 5; ++) printf(O%dP ,*a);

    a++; p = a; for( =0; 5; ++)

    printf(O%d P ,*p);p++;

    Answer:Compiler error: lvalue reDuired. Explanation:Error is in line with statement a%%. 6he operand must (e an lvalue and may (e of anyof scalar type for the any operator array name only when su(scripted is an lvalue.+imply array name is a non8modifia(le lvalue.

    -. main( ){ static int a[ ] = 0,1,2,!, ; int *p[ ] = a,a+1,a+2,a+!,a+ ; int **ptr = p; ptr++; printf(O n %d %d %dP, ptr p, *ptr a, **ptr);*ptr++;

    printf(O n %d %d %dP, ptr p, *ptr a, **ptr);*++ptr;

    printf(O n %d %d %dP, ptr p, *ptr a, **ptr);++*ptr;

    printf(O n %d %d %dP, ptr p, *ptr a, **ptr);}

    Answer: 222 ??? >>>

    >11

    8. main( ){ void *vp; char ch = Q R, *cp = O oof&P; int = 20; vp = ch; printf(O%cP, *(char *)vp);

  • 8/14/2019 C net apti (gud).doc

    17/32

    vp = ; printf(O%dP,*(int *)vp); vp = cp; printf(O%sP,(char *)vp + !);}

    Answer: g?3fy

    Explanation:+ince a void pointer is used it can (e type casted to any other type pointer. vp 9 Ichstores address of char ch and the next statement prints the value stored in vp after typecasting it to the proper data type pointer. the output is LgN. +imilarly the output fromsecond printf is L?3N. 6he third printf statement type casts it to print the string from the1th value hence the output is LfyN.

    50. main ( ){

    static char *s[ ] = O ac4P, O9hit#P, O o9P, Ovio #tP ; char **ptr[ ] = s+!, s+2, s+1, s , ***p; p = ptr; **++p; printf(O%sP,* *++p + !);}

    Answer: c0

    Explanation:,n this pro(lem we have an array of char pointers pointing to start of 1 strings. 6hen wehave ptr which is a pointer to a pointer of type char and a varia(le p which is a pointerto a pointer to a pointer of type char. p hold the initial value of ptr i.e. p 9 s%>. 6henext statement increment value in p (y 2 thus now value of p 9 s%?. ,n the printfstatement the expression is evaluated #%%p causes gets value s%2 then the predecrement is executed and we get s%2 U 2 9 s . the indirection operator now gets thevalue from the array of s and adds > to the starting address. 6he string is printedstarting from this position. 6hus the output is Lc0N.

    51. main(){ int i, n; char *3 = O ir P; n = str #n(3);

    *3 = 3[n]; for(i=0; i printf(O%s nP,3);3++;

    Answer:

    http://techpreparation.com/aptitute-questions/c-aptitude-questions6.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions6.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions6.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions6.htm
  • 8/14/2019 C net apti (gud).doc

    18/32

    $(lan0 space&irlrll Explanation:

    )ere a string $a pointer to char& is initiali ed with a value YgirlZ. 6he strlen functionreturns the length of the string thus n has a value 1. 6he next statement assigns valueat the nth location $LS3N& to the first location. 7ow the string (ecomes YS3irlZ . 7ow theprintf statement prints the string after each iteration it increments it starting position.oop starts from 3 to 1. 6he first time x 3! 9 LS3N hence it prints nothing and pointervalue is incremented. 6he second time it prints from x 2! i.e YirlZ and the third time itprints YrlZ and the last time it prints YlZ and the loop terminates.

    52. int i, ; for(i=0;i =10;i++) +=5;

    ass#rt(i 5);

    Answer:5untime error : A(normal program termination.

    assert failed $i;=&

    Explanation:asserts are used during de(ugging to ma0e sure that certain conditions are satisfied. ,fassertion fails the program will terminate reporting the same. After de(ugging use Qundef 7/EB-'and this will disa(le all the assertions from the source code . Assertionis a good de(ugging tool to ma0e use of.

    5!. main() int i= 1; +i; printf("i = %d, +i = %d n",i,+i);

    Answer: i 9 82 %i 9 82

    Explanation:

    -nary % is the only dummy operator in C. @here8ever it comes you can Must ignore it Must (ecause it has no effect in the expressions $hence the name dummy operator&.

    5 . hat ar# th# fi #s 9hich ar# a$tomatica & op#n#d 9h#n a G fi # is#3#c$t#dSAnswer:stdin stdout stderr $standard input standard output standard error &.

    http://techpreparation.com/aptitute-questions/c-aptitude-questions6.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions6.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions7.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions7.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions7.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions6.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions6.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions7.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions7.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions7.htm
  • 8/14/2019 C net apti (gud).doc

    19/32

    55. 9hat 9i # th# position of th# fi # mar4#rS a: fsee0$ptr 3 +EE[G+E6&H (: fsee0$ptr 3 +EE[GC-5&H Answer : a: 6he +EE[G+E6 sets the file position mar0er to the starting of the file.

    (: 6he +EE[GC-5 sets the file position mar0er to the current position of the file.

    5 . main() char nam#[10],s[12]; scanf(" "%[T "] "",s);

  • 8/14/2019 C net apti (gud).doc

    20/32

    Wou can create a varia(le of type void # (ut not of type void since void is an emptytype. ,n the second line you are creating varia(le vptr of type void # and v of type voidhence an error.

    0. main() char *str1="a cd"; char str2[]="a cd"; printf("%d %d %d",si7#of(str1),si7#of(str2),si7#of("a cd"));

    Answer:? = =

    Explanation:,n first si eof str2 is a character pointer so it gives you the si e of the pointer varia(le.,n second si eof the name str? indicates the name of the array whose si e is =$including the FS3F termination character&. 6he third si eof is similar to the second one.

    1. main() char not; not=?2; printf("%d",not);

    Answer:3

    Explanation:< is a logical operator. ,n C the value 3 is considered to (e the (oolean value A +E andany non8 ero value is considered to (e the (oolean value 65-E. )ere ? is a non8 erovalue so 65-E. d#fin# VFEWI 1 >d#fin# XK I 1 >d#fin# L EE 0 main() if(L EE) p$ts("L EE"); # s# if(VFEWI) p$ts("XK I"); # s#

    p$ts("VFEWI");

    Answer: 65-E

    Explanation: 6he input program to the compiler after processing (y the preprocessor is main$&{

    http://techpreparation.com/aptitute-questions/c-aptitude-questions7.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions7.htm
  • 8/14/2019 C net apti (gud).doc

    21/32

    if$3& puts$"7- "&H else if$82& puts$"65-E"&H else puts$" A +E"&H

    }Oreprocessor doesnFt replace the values given inside the dou(le Duotes. 6he chec0 (y ifcondition is (oolean value false so it goes to else. ,n second if 82 is (oolean value truehence "65-E" is printed.

    !. main() int 4=1; printf("%d==1 is ""%s",4,4==1S"XK I":"VFEWI");

    Answer:

    2992 is 65-EExplanation:@hen two strings are placed together $or separated (y white8space & they areconcatenated $this is called as "stringi ation" operation&. +o the string is as if it is givenas "Pd992 is Ps". 6he conditional operator$ \: & evaluates to "65-E".

    . main() int &; scanf("%d", &); CC inp$t iv#n is 2000 if( (&% ==0 &%100 ?= 0) 66 &%100 == 0 ) printf("%d is a #ap ar"); # s# printf("%d is not a #ap ar");

    Answer:?333 is a leap year

    Explanation:An ordinary program to chec0 if leap year or not.

    5. >d#fin# ma3 5 >d#fin# int arr1[ma3]

    main() t&p#d#f char arr2[ma3]; arr1 ist= 0,1,2,!, ; arr2 nam#="nam#"; printf("%d %s", ist[0],nam#);

    Answer:

    http://techpreparation.com/aptitute-questions/c-aptitude-questions8.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions8.htm
  • 8/14/2019 C net apti (gud).doc

    22/32

    Compiler error $in the line arr2 list 9 {3 2 ? > 1}&

    Explanation:arr? is declared of type array of si e = of characters. +o it can (e used to declare thevaria(le name of the type arr?. But it is not the case of arr2. )ence an error.5ule of 6hum(:

    Qdefines are used for textual replacement whereas typedefs are used for declaring newtypes.

    . int i=10; main() #3t#rn int i; int i=20; const vo ati # $nsi n#d i=!0; printf("%d",i);

    printf("%d",i); printf("%d",i);

    Answer:>3 ?3 23

    Explanation:F{F introduces new (loc0 and thus new scope. ,n the innermost (loc0 i is declared as

    const volatile unsignedwhich is a valid declaration. i is assumed of type int. +o printf prints >3. ,n the next(loc0 i has value ?3 and so printf prints ?3. ,n the outermost (loc0 i is declared asextern so no storage space is allocated for it. After compilation is over the lin0erresolves it to glo(al varia(le i $since it is the only varia(le visi(le there&. +o it prints iFsvalue as 23.

    /. main() int * ; int i=10; = i;

    printf("%d",* );}

    Answer:23

    Explanation: 6he varia(le i is a (loc0 level varia(le and the visi(ility is inside that (loc0 only. But the

    http://techpreparation.com/aptitute-questions/c-aptitude-questions8.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions8.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions8.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions8.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions8.htm
  • 8/14/2019 C net apti (gud).doc

    23/32

    lifetime of i is lifetime of the function so it lives upto the exit of main function. +ince thei is still allocated space #M prints the value stored in i since M points i.

    -. main() int i= 1; i; printf("i = %d, i = %d n",i, i);

    Answer:i 9 82 8i 9 2

    Explanation:8i is executed and this execution doesnFt affect the value of i. ,n printf first you Must printthe value of i. After that the value of the expression 8i 9 8$82& is printed.

    8. >inc $d#

    main() const int i= ; f oat ; = ++i; printf("%d %f", i,++ );

    Answer:Compiler error

    Explanation:i is a constant. you cannot change the value of constant

    /0. >inc $d#main(){ int a[2][2][2] = 10,2,!, , 5, ,/,- ; int *p,* ; p= a[2][2][2]; * =***a; printf("%d..%d",*p,* );}

    Answer:

    gar(agevalue..2

    Explanation:p9Ia ?! ?! ?! you declare only two ?/ arrays. (ut you are trying to access the third?/$which you are not declared& it will print gar(age values. #D9###a starting address ofa is assigned integer pointer. now D is pointing to starting address of a.if you print #DmeAnswer:it will print first element of >/ array.

    http://techpreparation.com/aptitute-questions/c-aptitude-questions8.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions8.htm
  • 8/14/2019 C net apti (gud).doc

    24/32

    /1. >inc $d#main() r# ist#r i=5; char []= "h# o";

    printf("%s %d", ,i);

    }

    Answer:hello =

    Explanation:if you declare i as register compiler will treat it as ordinary integer and it will ta0einteger value . i value may (e stored either in register or in memory.

    /2. main(){ int i=5, = ,7;

    printf("%d",i+++ );

    Answer:22

    Explanation:the expression i%%%M is treated as $i%% % M&

    http://techpreparation.com/aptitute-questions/c-aptitude-questions8.htmhttp://techpreparation.com/aptitute-questions/c-aptitude-questions8.htm
  • 8/14/2019 C net apti (gud).doc

    25/32

    Y. hat 9i # th# o$tp$t of th# fo o9in stat#m#nt S

    C* C* printf("h# o"); *C *C

    a) h# o) no o$tp$tc) #rrord) "h# o"

    FLW IK : G

    Explanation :

    7ested comments are not allowed in FCF.

    Notes : Comments should (e written in *# 88888888888888 #* without any nesting in (etween.

    Y. hat 9i # th# o$tp$t of th# fo o9in stat#m#nt S

    printf("%i",!5,2+-*5%10 2);

    a) #rror) 0c) !5d) !50

    FLW IK : G

    Explanation :

    printf$ "Pi " >= ?%T#=P238? &H

    As no format specifier is mentioned for the expression " ?%T#=P238? " hence only ">="will get printed on the screen.

    7otes :

    ormat specifiers

    int 8 Pi Pd

    float 8 Pf

    char 8 Pc

  • 8/14/2019 C net apti (gud).doc

    26/32

    Y. hat 9i # th# o$tp$t of th# fo o9in stat#m#nt S

    int a=10; printf("%d i",a,10);

    a) #rror) 10c) 10 10d) non# of th#s#

    FLW IK : N

    Explanation :

    int a 9 23H printf$" Pd Ii " a 23&H

    ormat specifier for "a" is mentioned hence value of "a" will get printed on screen . 7oformat specifier is mentioned for "23" hence it will not get printed on screen . +o finaloutput will (e "23 Ii".

    Y/. hat 9i # th# o$tp$t of th# fo o9in stat#m#nt S

    printf("%Z%3%ci%3",11,10,BsB,12);

    a) #rror) ascc) Das8 c

    d) non# of th#s#

    FLW IK : N

    Explanation :

    printf$"P]PxPciPx" 22 23 FsF 2?&H

    22 23 2? will get converted into eDuivalent hexadecimal entities .

    22 B

    23 8 a

    2? 8 c

    hence final output will (e "Basic".

  • 8/14/2019 C net apti (gud).doc

    27/32

    Y-. hat 9i # th# o$tp$t of th# fo o9in stat#m#nts S

    int a = printf("00"); printf("%d",a);

    a) 0) 00

    c) 002d) ar a # va $#

    FLW IK : G

    Explanation :

    int a 9 printf$"33"&H printf$"Pd" a&H

    printf$& function returns the num(er of characters (eing printed on screen. )ence "?"gets stored in varia(le "a". 6herefore the final output is "33?".

    Y8. hat 9i # th# o$tp$t of th# fo o9in stat#m#nts S

    int a = !, = -; printf("%d", a = );

    a) #rror) ar a # va $#c) !d) 1

    FLW IK : N

    Explanation :

    int a 9 > ( 9 TH printf$"Pd" a;9(&H

    6he condition "a;9(" is true hence "2" gets printed out.

    ,f the condition is false "3" gets printed out.

    Notes :

    'eneral orm :

    printf$"format string" list&H

    ist can contain varia(les constants or expressions . )owever list is optional.

    ,n the a(ove given pro(lem "a;9(" is an expression which is a perfectly valid syntax.

  • 8/14/2019 C net apti (gud).doc

    28/32

    Y10. hat 9i # th# o$tp$t of th# fo o9in stat#m#nts S

    int a = , = /,c; c = a = = ; printf("%i",c);

    a) 0) #rror

    c) 1d) ar a # va $#

    Explanation :

    int a 9 1 ( 9 R cH c 9 a 9 9 (H printf$"Pi" c&H

    6he condition $a 9 9 (& is false . )ence "3" gets stored in varia(le "c" which eventuallygets printed out.

    Y12. hat 9i # th# o$tp$t of th# fo o9in pro ram S

    >inc $d# stdio.h@>inc $d# math.h@void main() f oat a = !.2 ; printf("%f",c#i (a));

    a) .0) !.0c) !.2d) non# of th#s#

    FLW IK : F

    Explanation :

    float a 9 >.? H printf$"Pf" ceil$a&&H

    "ceil$&" function present in the header file "math.h" rounds up the value of "a" from">.? " to "1.3".

    7otes :

    "floor$&" function does the opposite of "ceil$&" function .i.e "floor$&" function rounds downthe value.

    or example : >.? to >.3

    Y 1!. hat 9i # th# o$tp$t of th# fo o9in stat#m#nts S

    int a = 5, = 2, c = 10, i = a@ c; printf("%d",i);

    a) #rror

  • 8/14/2019 C net apti (gud).doc

    29/32

    ) 1c) ar a # va $#d) 5

    FLW IK : D

    Explanation :

    int a 9 = ( 9 ? c 9 23 i 9 a (;cH printf$"Pd" i&H

    +ince $a (& is true it is replaced (y "2". 7ow "2" is compared with "c".

    +ince $2;23& is true it is replaced (y "2".

    Y 1 . hat 9i # th# o$tp$t of th# fo o9in pro ram S

    >inc $d# stdio.h@int a = 10;void main() int a = 50; printf("%d",a);

    a) 50) #rrorc) 10d) ar a # va $#

    FLW IK : F

    Explanation :

    Qinclude;stdio.h

    int a 9 23H ** "a" is a glo(al varia(le here

    void main$&

    { int a 9 =3H printf$"Pd" a&H } ** "a" is a local varia(le here

    @henever there is a conflict local varia(le enMoys a higher priority than glo(al varia(le.

    Y 15. hat 9i # th# o$tp$t of th# fo o9in pro ram S

    >inc $d# stdio.h@void main() #3t#rn int 3; printf("%d",3); int 3 = 10;

    a) #rror) 0

  • 8/14/2019 C net apti (gud).doc

    30/32

    c) ar a # va $#d) 10

    FLW IK : N

    Explanation :

    Qinclude;stdio.h

    void main$&

    { extern int xH ** declaration not definition

    printf$"Pd" x&H

    }int x 9 23H ** definition

    As declaration of external varia(le is already done in main$& hence definition ofexternal varia(le can (e done outside main$&.

    Y 1 . hat 9i # th# o$tp$t of th# fo o9in pro ram S

    >inc $d# stdio.h@void main() str$ct p

    int a,c ; f oat ;d = 1 ;printf("%d%d%f",d.a,d.c,d. );

    a) ar a # va $#) 100.0c) #rrord) 000.0

    FLW IK : D

    Explanation :

    void main$&

    { struct p

    { int a c H float (H }d 9 {2}H ** partiallyinitialised

    printf$"PdPdPf" d.a d.c d.(&H

    }

  • 8/14/2019 C net apti (gud).doc

    31/32

    )ere the structure $automatic storage class& is partially initialised.

    )ence the remaining elements of structure are initialised to "3"

    Y1-. hat 9i # th# o$tp$t of th# fo o9in stat#m#nts S

    int *a; f oat far * ; char h$ #*c

    printf("%d,%d,%d",si7#of(a),si7#of( ),si7#of(c));

    a) 222) c) 2d) 22

    FLW IK : G

    Explanation :

    6hree types of pointers are near far and huge. By default every pointer is a "nearpointer" unless and until "far" and "huge" 0eywords are defined with it.

    +i e of all the "near pointers" is "?" under /J+.

    +i e of all "far" and "huge" pointers is "1" under /J+.

    Y18 . hat 9i # th# o$tp$t of th# fo o9in stat#m#nts S

    f oat 4 = !.- ; printf("%d",(int)4);

    a) !.-) !.0c) !d)

    FLW IK : G

    Explanation :

    float 0 9 >.T1H printf$"Pd" $int&0&H

    6ypecasting is (eing done i.e float is (eing converted into int.

    >.T1 gets truncated to >.

    Y20 . inc $d# stdio.h@void main() printf("h# o"); main();

  • 8/14/2019 C net apti (gud).doc

    32/32

    a) 1) 2c) infinit# n$m #r of tim#sd) non# of th#s#

    FLW IK : N

    Explanation :

    Qinclude;stdio.h

    void main$&

    { printf$"hello"&H main$&H }

    6he program will printf "hello" till the stac0 doesnFt overflow.


Recommended