首页 > 试题广场 >

尽可能找出下列代码的bug:#include <...

[问答题]
 尽可能找出下列代码的bug:
#include <vector.h>

void main(int argc, char** argv)
{
  int n;
  if (argc > 1)
    n = argv[0];
  int* stuff = new int[n];
  vector<int> v(100000);
  delete stuff;
  return 0;
}
当n <= 1时,n是随机数,是整数也可能是负数,很有可能出现运行时错误。
并且当n > 1时,应该delete []stuff。

编辑于 2019-09-17 15:27:04 回复(0)