ผู้ประกอบการ c ++ sizeof
sizeof เป็นคำหลักที่มันเป็นผู้ประกอบการรวบรวมเวลาใช้ในการกำหนดตัวแปรหรือชนิดข้อมูลไบต์
ประกอบ sizeof สามารถนำมาใช้เพื่อให้ได้ระดับโครงสร้างยูเนี่ยนและผู้ใช้กำหนดขนาดชนิดข้อมูลอื่น ๆ
sizeof ใช้ไวยากรณ์ต่อไปนี้:
sizeof (data type)
ขัดแย้งชนิดข้อมูลเพื่อคำนวณขนาดของชนิดข้อมูลรวมทั้งการเรียนโครงสร้างยูเนี่ยนและผู้ใช้กำหนดชนิดข้อมูลอื่น ๆ
ลองตัวอย่างต่อไปนี้ในการทำความเข้าใจภาษา C ++, การใช้ sizeof คัดลอกและวางต่อไปนี้ C ++ โปรแกรม test.cpp แฟ้มรวบรวมและเรียกใช้โปรแกรม
#include <iostream> using namespace std; int main() { cout << "Size of char : " << sizeof(char) << endl; cout << "Size of int : " << sizeof(int) << endl; cout << "Size of short int : " << sizeof(short int) << endl; cout << "Size of long int : " << sizeof(long int) << endl; cout << "Size of float : " << sizeof(float) << endl; cout << "Size of double : " << sizeof(double) << endl; cout << "Size of wchar_t : " << sizeof(wchar_t) << endl; return 0; }
เมื่อโค้ดข้างต้นจะรวบรวมและดำเนินการก็จะก่อให้เกิดผลลัพธ์ต่อไปนี้ผลจะแตกต่างกันไปตามการใช้งานของตัวเครื่อง:
Size of char : 1 Size of int : 4 Size of short int : 2 Size of long int : 4 Size of float : 4 Size of double : 8 Size of wchar_t : 4