© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

Ex 1: What is the output?

char *foo()
{
char result[100]);
strcpy(result,"anything is good");
return(result);
}
void main()
{
char *j;
j=foo()
printf("%s",j);
}

Ans: anything is good.

Ex - 2:  Is the following code legal?
void main()
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}

Ans: 20 20 20

Ex - 3 What is the outputl?
void main()
{
char *s="\12345s\n";
printf("%d",sizeof(s));
}

Ans: 6

Ex - 4 What is the outputl?
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);
}

Ans:
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.


1 >> 2 >> 3 >> 4 >> 5 >> 6 >> 7 >> 8 >> 9
SLogix Student Projects
bottom