Stack and Heap Addresses

I tried to just allocate memory on the stack and heap in C.

int x = 2;
int *y = malloc(sizeof(int));

When I look at the address x on the stack and the heap address contained in y, I see the following

x stack address : 0xbfe92bb4
heap address in y : 0x 9c4b008

Are these addresses in a different format (since I do not see the same hexadecimal characters in both of them)?

+5
source share
3 answers

There are three main types of distributions in a conventional software model:

  • Static - mainly for global / static variables - it is allocated during program loading (usually during compilation of predefined memory addresses, depending on the program loading model).
  • - (, malloc ), " ", .
  • -

- , - ( -), (, , , ) ( ).

- ( , , 0x09c4b008, 0 ).

+4

.

, . -. , , char s [] = "hello world" C, C, int debug = 1 , . C, const char * string = "hello world" , "hello world" -. : int = 10 , int = 10

Heap BSS . "" malloc, realloc free, brk sbrk ( , brk/sbrk " " malloc/realloc/free, mmap . .

wikipedia

+4

Malloc , , .

The different format is not the difference in format, but simply the fact of where the memory exists in the process space, which partially depends on the decision of the compiler and the OS when allocating the heap of space for malloc.

See also this question , which has much more detailed information.

+1
source

All Articles