这是在堆栈和堆上分配指针的正确方法吗?如果不是,那么正确的方法是什么?
int a=7;
int* mrPointer=&a;
*mrPointer;
int** iptr; // iptr is on stack
*iptr=mrPointer; //not OK
int** iptr_h = new int*(); // iptr_h is on heap
*iptr_h=mrPointer;
感谢 Mat 的回答,现在我知道这是将其放入堆栈的正确方法:
int** iptr; // iptr is on stack
iptr=&mrPointer;
这在堆上:
int** iptr_h = new int*(); // iptr_h is on heap
*iptr_h=mrPointer;