33,311
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
#define ARRAY(TYPE, NAME, LEFT, RIGHT) TYPE __myarray_##NAME[(RIGHT-LEFT)+1]; TYPE *NAME = NAME - LEFT;
int main()
{
int l, r;
cin >> l >> r;
ARRAY(unsigned long long, test, l, r);
for (int i = l; i <= r; ++i)
cout << "&test[" << i << "] = " << &test[i] << endl;
cout << "sizeof test :" << sizeof test << endl;
cout << "sizeof __myarray_test :" << sizeof __myarray_test << endl;
string str('a', 10000);
cout << "sizeof str :" << sizeof str << endl;
cout << "sizeof &str :" << sizeof &str << endl;
int (*iarr)[10];
cout << "sizeof iarr :" << sizeof iarr << endl;
cout << "sizeof *iarr :" << sizeof *iarr << endl;
int *(iarr2[10]);
cout << "sizeof iarr2 :" << sizeof iarr2 << endl;
cout << "sizeof *iarr2 :" << sizeof *iarr2 << endl;
cout << endl;
return 0;
}
&test[1] = 0x400983
&test[2] = 0x40098b
&test[3] = 0x400993
&test[4] = 0x40099b
&test[5] = 0x4009a3
&test[6] = 0x4009ab
&test[7] = 0x4009b3
&test[8] = 0x4009bb
&test[9] = 0x4009c3
&test[10] = 0x4009cb
sizeof test :8
sizeof __myarray_test :80
sizeof str :8
sizeof &str :8
sizeof iarr :8
sizeof *iarr :40
sizeof iarr2 :80
sizeof *iarr2 :8