260. What is bug in this code? correct it......
Microsoft Interview Questions and Answers
(Continued from previous question...)
260. What is bug in this code? correct it......
Question:
char * copy(char *p)
{
char buf[1000] = {0};
//copy algo[I skipped code here]
return buf;
}
what is bug in this code? correct it.
maybe an answer:
There are 2 bugs in this code.
First, is that if the length of source string is greater than 1000, we will have buffer overflow here and crush.
Second - returning the adress of local variable. the return value shall be allocated using new operator.
(Continued on next question...)
Other Interview Questions
|