Interview Questions

253.What is the output? What is the problem with the code if any?.....

Microsoft Interview Questions and Answers


(Continued from previous question...)

253.What is the output? What is the problem with the code if any?.....

Question:
char* NewLine(char* s)
{
char buffer[1024];
l = strlen(s);
strcpy(s,buffer);
s[l]='\n'; // Add a new line character to s;
return s;
}
What is the output? What is the problem with the code if any?


maybe an answer:


char* NewLine(char* s)
{
char buffer[1024];
l = strlen(s);
if(I
1023){
strcpy(s,buffer);
buffer[l]='\n'; // Add a new line character to s;
buffer[I]='\n';
return buffer;
}
else
return null
; }



maybe an answer2:


char* newline(char* s)
{
int l = strlen(s)
; static char buffer[1024];
strcpy(buffer,s);
l = strlen(buffer);
buffer[l]='\n';
buffer[l+1]='\0';
return buffer; }

(Continued on next question...)

Other Interview Questions