C Interview Questions And Answers

adplus-dvertising
C FAQS
Previous Home Next

Q:What will be printed as the result of the operation below:
main()
{
int x=20,y=35;
x=y++ + x++;
y= ++y + ++x;
printf(“%d%d\n”,x,y)
;
}
Ans: 5794

Q:What will be printed as the result of the operation below:
main()
{
int x=5;
printf(“%d,%d,%d\n”,x,x<<2,>>2)
;
}
Ans: 5,20,1

Q:What will be printed as the result of the operation below:

#define swap(a,b) a=a+b;b=a-b;a=a-b;
void main()
{
int x=5, y=10;
swap (x,y);
printf(“%d %d\n”,x,y)
; swap2(x,y);
printf(“%d %d\n”,x,y)
; }
int swap2(int a, int b)
{
int temp;
temp=a;
b=a;
a=temp;
return 0;
}
as x = 5 = 0×0000,0101; so x << 2 -< 0×0001,0100 = 20; x >7gt; 2 -> 0×0000,0001 = 1. Therefore, the answer is 5, 20 , 1

the correct answer is
10, 5
5, 10

Answer: 10, 5

Q:What will be printed as the result of the operation below:

main()
{
char *ptr = ” Tech Preparation”;
*ptr++; printf(“%s\n”,ptr)
; ptr++;
printf(“%s\n”,ptr);

}
1) ptr++ increments the ptr address to point to the next address. In the previous example, ptr was pointing to the space in the string before C, now it will point to C.

2)*ptr++ gets the value at ptr++, the ptr is indirectly forwarded by one in this case.

3)(*ptr)++ actually increments the value in the ptr location. If *ptr contains a space, then (*ptr)++ will now contain an exclamation mark.

Ans:Tech Preparation


Q: What will be printed as the result of the operation below:
main()
{
char s1[]=“Tech”;
char s2[]= “preparation”;
printf(“%s”,s1)
; }
Ans:Tech

Q:What will be printed as the result of the operation below:

main()
{
char *p1;
char *p2;
p1=(char *)malloc(25);
p2=(char *)malloc(25);
strcpy(p1,”Tech”);
strcpy(p2,“preparation”);
strcat(p1,p2);
printf(“%s”,p1)
;
}
Ans:Techpreparation
Previous Home Next