+ 1
What is heap and stack in memory allocation, and what is run time memory allotments... Please can someone explain it with basics
4 Respostas
+ 3
heap and stack are two parts of memory . the memory divided into two parts heap which Is run time memory allocation and other one is stack which is compile time memory allocation .
example of stack:
int a,b;
cin>>a>>b;
cout << a<<b;
when we run the program the , a and b move to the stack memory location .
example of heap:
int *arr ,n;
cin>>n;
arr=new int[n];
when we run this code the arr pointer will generate in heap as dynamic/run time memory allocation,
this is commonly used when we want to enter the total values enter in an array from the user.
0
well, run time memory allocation would be a dynamic one. In c++ for dynamic allocation you would use an implemented function new, in c it would be malloc, calloc and realloc. for freeing up the memory you have taken you use free, so you don't fill every possible free space xD. Heap and Stack are memory structures, I don't know how to explain the heap, but a stack is very obvious. you have a stucture that says that the last element you put in it is the first to go for some operation. You can probably find better answers kn stack overflow and the implementations of these structures
0
I mainly used stack in assembly, I'm only a beginner programmer so my knowledge is a bit limited. Hope this helps
0
I need to find the three maximum values in an array. For example, if we start with the following array:
A = [4,3,2,90,16,78]
It will be required to return the answer as 90,78 and 16? In order to obtain these values, I am required to use a max-heap. Your program should read an input file with numbers in it.