Using pointer declared in other function, in main.
Hello,
I've got the following code:
Code:
#include <stdio.h>
void test();
int main()
{
test();
printf("%s",ptr);
return 0;
}
void test()
{
char *ptr;
ptr = "Hello!";
}
Someone explained to me on IRC that string literals have static storage. So one would expect the preceding code to work. It however gives me a compiler error:
Code:
testcase.c: In function ‘main’:
testcase.c:7: error: ‘ptr’ undeclared (first use in this function)
Could somebody clarify this for me?
Thank You