Saturday, 17 August 2013

what's the output of following code and why?

what's the output of following code and why?

The following code is an interview qusetion and I can't understand the
output. Can anyone help? Thanks.
#include <stdio.h>
char* string_1()
{
char* p = "ABCD";
return p;
}
char* string_2()
{
char p[] = "ABCD";
return p;
}
int main(void)
{
printf("%s\n",string_1());
printf("%s\n",string_2());
}

No comments:

Post a Comment