【发布时间】:2013-11-13 03:32:05
【问题描述】:
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
【问题讨论】:
-
见this问题及相应答案。