Tuesday, 28 August 2012

Frequently Asked Questions in Technical Round at MNCs like TCS, WIPRO, INFOSYS,..etc – 15

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


1)

main()

{

int i=_l_abc(10);


printf("%d\n",--i);


}

int _l_abc(int i)

{

 return(i++);


}

Answer:

9


Explanation:

return(i++) it will first return i and then increments. i.e. 10 will be returned.


2)

main()

{

 char *p;


 int *q;


 long *r;


 p=q=r=0;


 p++;


 q++;


 r++;


 printf("%p...%p...%p",p,q,r);


}

Answer:

0001...0002...0004


Explanation:

++ operator  when applied to pointers increments address according to their corresponding data-types.


3)

main()

{

 char c=' ',x,convert(z);


 getc(c);


 if((c>='a') && (c<='z'))


 x=convert(c);


 printf("%c",x);


}

convert(z)

{

  return z-32;


}

Answer:

Compiler error


Explanation:

declaration of convert and format of getc() are wrong.

No comments:

Post a Comment