20-sizeof
#include <iostream>
using namespace std;
int main()
{//用 sizeof 計算各類種常量的字節長度cout << "sizeof('$')=" << sizeof('$') << endl;cout << "sizeof(1)=" << sizeof(1) << endl;cout << "sizeof(1.5)=" << sizeof(1.5) << endl;cout << "sizeof(\"Good!\")=" << sizeof("Good!") << endl;//用sizeof 計算各類型變量的字節長度int i = 100;char c = 'A';float x = 3.1416;double p = 0.1;cout << "sizeof(i)=" << sizeof(i) << endl;cout << "sizeof(c)=" << sizeof(c) << endl;cout << "sizeof(x)=" << sizeof(x) << endl;cout << "sizeof(p)=" << sizeof(p) << endl;//用sizeof 計算表達式的字節長度cout << "sizeof(x+1.732)=" << sizeof(x + 1.732) << endl;//用 sizeof 計算各類型的字節長度cout << "sizeof(char)=" << sizeof(char) << endl;cout << "sizeof(int)=" << sizeof(int) << endl;cout << "sizeof(float)=" << sizeof(float) << endl;cout << "sizeof(double)=" << sizeof(double) << endl;//用sizeof 計算數組的字節長度char str[] = "This is a test.";int a[10];double xy[10];cout << "sizeof(str)=" << sizeof(str) << endl;cout << "sizeof(a)=" << sizeof(a) << endl;cout << "sizeof(xy)=" << sizeof(xy) << endl;//用sizeof 計算自定義類型的長度struct st {short num;float math_grade;float Chinese_grade;float sum_grade;};st student1;cout << "sizeof(st)=" << sizeof(st) << endl;cout << "sizeof(student1)=" << sizeof(student1) << endl;
}
總結
- 上一篇: 相学java_从这两套题,重新认识JS的
- 下一篇: stackexchange.mysql_