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

C and C++ Interview Questions

1. What are the advantages of auto variables?

Ans:

1)  The same auto variable name can be used in different blocks.
2)  There is no side effect by changing the values in the blocks.
3)  The memory is economically used.
4)   Auto variables have inherent protection because of local scope.

Ex - 1: What is the output?
   main()
      {
      char a;
      a=!2;
      printf("%d",a);
      }
Ans:
0
Explanation:
! is a logical operator. In C the value 0 is considered to be the boolean value FALSE, and any non-zero

value is considered to be the boolean value TRUE. Here 2 is a non-zero value so TRUE. !TRUE is FALSE (0) so it prints 0.

Ex - 2: What is the output?
main(){
 char a[100];
 a[0]='a';a[1]]='b';a[2]='c';a[4]='d';
 abc(a);
}
abc(char a[]){
 a++;
       printf("%c",*a);
 a++;
 printf("%c",*a);
}

Ans: bc

Explanation:
The base address is modified only in function and as a result a points to 'b' then after incrementing to 'c'  so bc will be printed.          

Ex - 3: What is the output?

void main()
{
      char a[]="12345\0";
      int i=strlen(a);
      printf("here in 3 %d\n",++i);
}
Ans:
here in 3 6
Explanation:

The char array 'a' will hold the initialized string, whose length will be counted from 0 till the null character. Hence the 'I' will hold the value equal to 5, after the pre-increment in the printf statement, the 6 will be printed.


SLogix Student Projects
bottom