now i want to create a function, the protptype of this function:
char *sFunc()
{
return "hi world!";
}
any problem with this function? because i'm returning a address. and this address..i don't know how to classify it. it's allocated address or whatever?
or even:
char *sFunc()
{
char *s = (char *) malloc(sizeof(char) * 30);
s = "hi world!";
return s;
}
if i allocate like this, am i need to free it afterward (in order to recover the memory...) using free()?
and, why we need no allocate new memory to a char pointer before do this?
char *s = "hello!";
char *sFunc()
{
return "hi world!";
}
any problem with this function? because i'm returning a address. and this address..i don't know how to classify it. it's allocated address or whatever?
or even:
char *sFunc()
{
char *s = (char *) malloc(sizeof(char) * 30);
s = "hi world!";
return s;
}
if i allocate like this, am i need to free it afterward (in order to recover the memory...) using free()?
and, why we need no allocate new memory to a char pointer before do this?
char *s = "hello!";