Possible duplicate:Returns a string literal address from a safe and portable function?"life" of a string literal in C
Hi i'm a little confused
char *func() { return "Hello"; }
Here "Hello" is a sequence / array of characters. This is a local variable, and it should disappear as soon as the function returns. Then how is it that we can get the right value?
"Hello"is a string literal and will exist for the lifetime of the program. To quote the relevant sections of the C99 standard:
"Hello"
... , , ...
, , static . - , .
const char*, - undefined.
const char*
.
., , return, "Hello" , ;
: ?
( malloc() free()), , . .