There are three kinds of memory: static memory (static variables/members, global variables), stack, and heap.
The definition of global variables is variables defined outside of any functions.
I am wondering about the code below,
#include<iostream>
int *test=new int[5]();
int main(){
return 0;
}
It could be compiled and run. But what I am wondering is, where is that array allocated? Is it a global variable on the heap?
C++ Primer says that global variables will be freed when the program finishes. My question is, does this happen even if they are on the heap?