Tuesday, 6 March 2012

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

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


1)

#include<stdio.h>

main()

{

  int a[2][2][2] = { {10,2,3,4}, {5,6,7,8}  };


  int *p,*q;


  p=&a[2][2][2];


  *q=***a;


  printf("%d..%d",*p,*q);


}

Answer:

garbagevalue..1


Explanation:

p=&a[2][2][2]  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. *q=***a starting address of a is assigned integer pointer. now q is pointing to starting address of a.if you print *q meAnswer:it will print first element of 3D array.


2)

#include<stdio.h>

main()

{

   const int i=4;


   float j;


   j = ++i;


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


 }

Answer:

Compiler error


Explanation:

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


3)

#include<stdio.h>

main()

{

    register i=5;


    char j[]= "hello";


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


}

Answer:

hello 5


Explanation:

if you declare i as register  compiler will treat it as ordinary integer and it will take integer value. i value may be  stored  either in register  or in memory.

No comments:

Post a Comment