Interview Questions

229. What is the output of the program... .....

Microsoft Interview Questions and Answers


(Continued from previous question...)

229. What is the output of the program... .....

Question:
void copystring(char* dest, char *source)
{
while(*source != NULL)
{
*dest = *source;
dest++;
source++;
}
}

int _tmain(int argc, _TCHAR* argv[])
{
char input[10] = "hello";
char *dest;

dest = &input[1];

copystring(dest, input);

return 0;
}

What is the output of the program...


maybe an answer:


This is the case of exceeding the bounds of an array.. The program will crash at some point ... because the null value in the input array has been overwritten by 'h' hence source will never find null and will never terminate.

(Continued on next question...)

Other Interview Questions