A
Aarti
I have a very elementary question about pointers. Please pardon me
for my ignorance of C
int main()
{
int* i;
*i = 1 //at times this may give me a core dump.
const char* str = "test"; //This seems to be a valid construct.
}
Now I understand that when we declare int* i, we just have a pointer
that may point to any place. If we try to store something in it, we
may get a segmentation fault. But why does const char* str = "test"
work? Do we not need to allocate memory for str first? Can someone
please shed some light on this?
Thanks in advance
for my ignorance of C
int main()
{
int* i;
*i = 1 //at times this may give me a core dump.
const char* str = "test"; //This seems to be a valid construct.
}
Now I understand that when we declare int* i, we just have a pointer
that may point to any place. If we try to store something in it, we
may get a segmentation fault. But why does const char* str = "test"
work? Do we not need to allocate memory for str first? Can someone
please shed some light on this?
Thanks in advance