Possible Duplicate:
C String literals: Where do they go?
As far as I know,
generally, pointer have to be allocated by malloc(), and will be allocated to heap, then unallocated by free();
and
non pointer(int,char,float,etc..) will be allocated automatically to stack, and unallocated as long as the function go to return
but, from following code :
#include <stdio.h>
int main()
{
char *a;
a = "tesaja";
return 0;
}
where will a allocated to ? stack or heap ?
The string literal will be allocated in data segment. The pointer to it,
a, will be allocated on the stack.Your code will eventually get transformed by the compiler into something like this:
Therefore, the exact answer to your question is: neither. Stack, data, bss and heap are all different regions of memory. Const static initialized variables will be in data.