小编Ros*_*oss的帖子

为什么用new创建的C++数组的行为与C风格数组不同?

我正在自学C++,因此一直在编写一些示例代码来真正指出我对指针和数组的理解.

我写了这个:

int myints[] = {20, 40, 60, 80, 100}; 
// C style array? should be stored on stack? is myint's type pointer to int or an array of int? how does it differ from myotherints?

int* myotherints = new int[5]{20, 40, 60, 80, 100}; // new always returns pointer, is this a C++ style array?     
// does this pointer get created on stack while the elements themselves are created in free heap?

int j = 5; // should be …
Run Code Online (Sandbox Code Playgroud)

c c++ arrays pointers

5
推荐指数
3
解决办法
724
查看次数

标签 统计

arrays ×1

c ×1

c++ ×1

pointers ×1