Global memory management in C++ : Stack or Heap?


Stack and heap are used to store variables during the execution of the program and it also get destroyed.

Global data structures or global variables are not consumed by stack or heap. They basically allocated in a fixed memory block, which remains unchanged.

int a[10]; // located in a fixed memory block
int main() {
   int main() {
      float *ptr = (int *)malloc(sizeof(float)10.0)); //use heap.
   }
}

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements