I wrote the following C program.
int main() {
int i = 3;
char *q = "hello";
char *p = NULL;
return 0;
}
When I compile and debug it with gdb, I get the following reg information..
gcc main.c -g
gdb a.out
info reg:
cs 0x33 51
ss 0x2b 43
ds 0x0 0
My question is if ds
is 0, how integer i
and char* q
are getting their physical address?
This is compiler dependent.A data segment is a portion of virtual address space of a program, which contains the global variables and static variables that are initialized by the programmer.Global and statically allocated data that initialized to zero by default are kept in what is called the BSS area of the process.The heap is where dynamic memory (obtained by malloc(), calloc(), realloc() and new – C++) comes from. . A stack segments is where local (automatic) variables are allocated. So i ,p and q are stored in stack segment.A code segment contains compiled program. RO (read only) segment contains constant string like "Hello"