Wow thanks for the quick reply :)
1. The heap is used to allocate dynamic memory. You allocate memory from it using malloc(), realloc(), calloc() (etc.) (C) or new (C++).
I think it also gets memory from the OS when it can't find a big enough block or doesn't have enough memory left to it.
2. The stack allows functions to return to the point of execution after they were called; e.g.
1 2 3 4
|
int main() {
myFunction(); // After myFunction returns, it is popped off of the stack and execution begins at the next instruction
return 0;
}
|
*
3. malloc() returns a void pointer to a block of memory (if a big enough block is found), new returns the reference of a block of memory (possibly a pointer to the first byte(s) (depending on type, i.e. sizeof(int) on an x86 should be 4)).
free() takes a void* parameter (pointer to a block of memory) and deallocates it (returns it to the heap). delete deallocates the memory of a variable.
Additionally malloc and free are functions, new and delete are operators.
4. I would guess because an array (without a subscript) is a pointer to the first element of the array (i.e. the [0] element), so if you use ordinary delete on it, you would only delete the memory at array[0] rather than all of array.
5. I'm not sure. Logically I would say true, because pInt doesn't point to anything anymore. However, you haven't deleted the address... I'm going to go for true...
Edit:
* the stack also allocates static variables.