regarding variables.

This is a discussion on regarding variables. within the C Programming forums, part of the General Programming Boards category; please help me regarding the below issues.
1)
where do gloabl variables are stored...i mean like local variables int a;
...

regarding variables.

please help me regarding the below issues.

1)
where do gloabl variables are stored...i mean like local variables int a;
are stored in stack.
2)
int a, *b;
in the above case the variables are stored in stack
now
char *a = "hello world"
in the above case pointer "a" would be stored in stack as its a local variable now where is the value string is stored.."hello world"
also there should have been some kind of memory allocation should have been done ... but automatically its happening ..so is the complier internally calling the malloc function to allocate for the string " hello world"..in that case the string would be stored in heap...plz help me

1)
where do gloabl variables are stored...i mean like local variables int a;
are stored in stack.

Globals are stored in the program's data segment.

Originally Posted by kiranck007

2)
int a, *b;
in the above case the variables are stored in stack
now
char *a = "hello world"
in the above case pointer "a" would be stored in stack as its a local variable now where is the value string is stored.."hello world"
also there should have been some kind of memory allocation should have been done ... but automatically its happening ..so is the complier internally calling the malloc function to allocate for the string " hello world"..in that case the string would be stored in heap...plz help me

The string "hello world" is a string literal that is stored in a segment of the programs memory like the data segment (but is marked usually as read-only) but may be called something else (anybody?). It is NOT allocated via a malloc call, the pointer "a" simply is set to the address of this memory segment where the text resides.

"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens

thanks

Originally Posted by hk_mp5kpdw

Globals are stored in the program's data segment.

The string "hello world" is a string literal that is stored in a segment of the programs memory like the data segment (but is marked usually as read-only) but may be called something else (anybody?). It is NOT allocated via a malloc call, the pointer "a" simply is set to the address of this memory segment where the text resides.