void main()
{
char *p = "hello";
}
What is the storage type of P and where points in memory(stack/data segment)? Where the string "helllo" stored?
The string is stored in read-only memory. The pointer itself is stored on the stack of main.
Unless your compiler documentation explicitly says that void main() is a legal signature, use int main(void) instead:
int main(void)
{
char *p = "hello";
return 0;
}
Exactly where the memory for p and the string "hello" are allocated will vary with the implementation. For both ELF and PE/COFF formats, the memory for p will be inside of the stack frame for main and the memory for "hello" will be in a read-only data segment (.rdata for PE/COFF, .rodata for ELF).
Your string sotred in the memory, and the pointer refer to the memory address wehere the string is stored. If you call this pointer it's return whit the memory address, and you can use this.
.rodatasegment.