我知道我不应该使用 Dev-C++,但它在学校是强制性的,所以我对此无能为力。
主题是 C/C++ 中的指针,并且在测量整数数组的长度时出现错误。请看下面的代码:
// POINTER
# include<iostream>
# include<string.h>
using namespace std;
int main(){
//neues Feld anlegen
int *a = new int[5];
a[0] = 12;
a[1] = 5;
a[2] = 43;
a[3] = -12;
a[4] = 100;
// Feld füllen
for(int i = 0; i<sizeof(a);i++){
cout<<a[i]<<"\n"<<endl;
}
cout<<sizeof(a);
system("pause");
return 0;
}
sizeof() 返回 4 而不是 5...有什么想法吗?