我有这样的代码:
int *x[2];
int var0 = 10;
int var1 = 20;
int var2 = 30;
x[0] = &var0;
x[1] = &var1;
x[2] = &var2;
cout << "var0 is equal to: " << *x[0] << endl;
var0 is equal to: 32767
我所期待的:
- 我已经用 3 个项目初始化了指针数组
- 为 3 个变量分配了一些值
- 将此变量的地址分配给指针数组项
- 现在我期待:
*x[0] = 10, *x[1] = 20, *x[2] = 30
,但正如您从示例中看到的那样*x[0] == 32767
。为什么?