C Language Interview Question
There are many things that you can do ahead of time to prepare for the interviewing process, and move yourself a step above of the competition. Updating your resume and reviewing frequently asked interview questions can be very effective, and goes a long way in getting the most out of your interview.
What will print out?
main()
{
char *p1=“name”;
char *p2;
p2=(char*)malloc(20);
memset (p2, 0, 20);
while(*p2++ = *p1++);
printf(“%s\n”,p2);
}
The pointer p2 value is also increasing with p1 .
*p2++ = *p1++ means copy value of *p1 to *p2 , then increment both addresses (p1,p2) by one , so that they can point to next address . So when the loop exits (ie when address p1 reaches next character to “name” ie null) p2 address also points to next location to “name” . When we try to print string with p2 as starting address , it will try to print string from location after “name” … hence it is null string ….
e.g. :
initially p1 = 2000 (address) , p2 = 3000
*p1 has value “n” ..after 4 increments , loop exits … at that time p1 value will be 2004 , p2 =3004 … the actual result is stored in 3000 - n , 3001 - a , 3002 - m , 3003 -e … we r trying to print from 3004 …. where no data is present … that's why its printing null .
Answer: empty string.
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)
;
}
Answer : 5794
What will be printed as the result of the operation below:
main()
{
int x=5;
printf(“%d,%d,%d\n”,x,x<<2,>>2)
;
}
Answer: 5,20,1
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
-
Technical Questions
- General Question (1017)
- HTML Question (500)
- XHTML Question (400)
- XML Question (652)
- CSS Question (400)
- CSS2 Question (358)
- AJAX Question (302)
- JavaScript Question (562)
- FLASH Question (622)
- Dot Net Technology Question (645)
- ASP Dot Net Question (242)
- Web Services Question (644)
- C # Question (754)
- C Question (302)
- C++ Question (622)
- JAVA Question (372)
- Testing Question (852)
- MySQL Server (322)
- Oracle Question (354)
- ASP Question (245)
- PHP Question (847)
- Visual Basic Question (748)
- MS Access Query Question (645)
- Linux Question (684)
- Unix Question (642)
- SAP Question (546)
- PERL Question (754)
- Python Question (984)
- Networking Question (372)
- Operting System Question (382)
All Information about Interview. Tips and Guideline. www.interviewGHOST.com
What Users Asked:
Advertisement Area :