小编Ge *_*Yan的帖子

我是否需要删除在堆中创建的堆栈中的指针?

int *createInt()
{
   int *a = new int;
   return a;
}

int main()
{
   int *x = createInt();
   *x = 10;
   cout << *x << '\n';
   delete x; // do I need this?
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

我需要删除x吗?如果不这样做,会导致内存泄漏问题吗?

c++ pointers memory-management

1
推荐指数
1
解决办法
576
查看次数

标签 统计

c++ ×1

memory-management ×1

pointers ×1