void nothing(int* buffer)
{
int* temp = new int[5];
for (int i = 0; i < 5; i++)
{
temp[i] = i;
}
buffer = temp;
}
void main(int argc, char* argv[])
{
int* a = new int;
nothing(a);
for (int i = 0; i < 5; i++)
{
cout << a[i] << endl;
}
system("pause");
}
为什么我不能从缓冲区获取新地址?我正在尝试将数组(指针)传递给函数并在内部修改它。
输出:
-842150451
-33686019
-1414812757
-1414812757
0
预期的:
0
1
2
3
4