memory allocation in Stack and Heap

前端 未结 6 499
抹茶落季
抹茶落季 2020-12-08 00:49

This may seem like a very basic question, but its been in my head so:

When we allocate a local variable, it goes into stack. Similarly dynamic allocation cause the v

6条回答
  •  爱一瞬间的悲伤
    2020-12-08 01:43

    The pointer variable itself would reside on the stack. The memory that the pointer points to would reside on the heap.

    int *i = malloc(sizeof(int));
    

    i would reside on the stack, the actual memory that i points to *i would be on the heap.

提交回复
热议问题