L
loudking
Hello all, please take a look at following code:
#include <stdio.h>
#include <stdlib.h>
char* GetChar()
{
char *c= "Automatic";
return c;
}
int main(int argc, char*argv[])
{
char *c= GetChar();
printf("c=%c\n", *c);
return 0;
}
I think variable c in GetChar is an automatic variable, and it should
be destroyed immediatly after the function is called. Then the array
that c is pointing to should be freed as well - GetChar is not
mallocing any address.
Could anybody explain why the caller (main) is still reaching the
correct address, please?
#include <stdio.h>
#include <stdlib.h>
char* GetChar()
{
char *c= "Automatic";
return c;
}
int main(int argc, char*argv[])
{
char *c= GetChar();
printf("c=%c\n", *c);
return 0;
}
I think variable c in GetChar is an automatic variable, and it should
be destroyed immediatly after the function is called. Then the array
that c is pointing to should be freed as well - GetChar is not
mallocing any address.
Could anybody explain why the caller (main) is still reaching the
correct address, please?