Monday, 12 March 2012

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

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


1)

struct point

{

 int x;


 int y;


 };

struct point origin,*pp;

main()

{

pp=&origin;


printf("origin is(%d%d)\n",(*pp).x,(*pp).y);


printf("origin is (%d%d)\n",pp->x,pp->y);


}

Answer:

origin is(0,0)


origin is(0,0)


Explanation:

pp is a pointer to structure. we can access the elements of the structure either with arrow mark or with indirection operator.


Note: Since structure point  is globally declared x & y are initialized as zeroes


2)

main()

{

int i=5,j=6,z;


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


}

Answer:

11


Explanation:

the expression i+++j is treated as (i++ + j)


3)

struct aaa

{

struct aaa *prev;


int i;


struct aaa *next;


};

main()

{

 struct aaa abc,def,ghi,jkl;


 int x=100;


 abc.i=0;abc.prev=&jkl;


 abc.next=&def;


 def.i=1;def.prev=&abc;def.next=&ghi;


 ghi.i=2;ghi.prev=&def;


 ghi.next=&jkl;


 jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;


 x=abc.next->next->prev->next->i;


 printf("%d",x);


}

Answer:

2


Explanation:

above all statements form a double circular linked list;


abc.next->next->prev->next->i


this one points to "ghi" node the value of at particular node is 2.

No comments:

Post a Comment