##sizeof查看定义的数组所占用字节数
#include<iostream>
int main(){using namespace std;int Inter [10];short sh [10];char ch [10];long lg [10];float fl [10];double dou [10];cout << "int style has " << sizeof Inter << " bytes.\n";cout << "short style has " << sizeof sh << " bytes.\n";cout << "char style has " << sizeof ch << " bytes.\n";cout << "long style has " << sizeof lg << " bytes.\n";cout << "float style has " << sizeof fl << " bytes.\n";cout << "double style has " << sizeof dou << " bytes.\n";return 0;
}
运行结果:
也就是说,数组所申请的空间大小是他的数组类型所占用字节与数组的数据个数的乘积。