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