ประเภทข้อมูล C++
ประเภทข้อมูล C++
ตามที่อธิบายไว้ใน บท ตัวแปรตัวแปรใน C++ ต้องเป็นประเภทข้อมูลที่ระบุ:
ตัวอย่าง
int myNum = 5;
// Integer (whole number)
float myFloatNum = 5.99;
// Floating point number
double myDoubleNum = 9.98; // Floating point number
char myLetter = 'D';
// Character
bool
myBoolean = true; // Boolean
string myText = "Hello";
// String
ประเภทข้อมูลพื้นฐาน
ชนิดข้อมูลระบุขนาดและประเภทของข้อมูลที่ตัวแปรจะจัดเก็บ:
Data Type | Size | Description |
---|---|---|
int |
4 bytes | Stores whole numbers, without decimals |
float |
4 bytes | Stores fractional numbers, containing one or more decimals. Sufficient for storing 7 decimal digits |
double |
8 bytes | Stores fractional numbers, containing one or more decimals. Sufficient for storing 15 decimal digits |
boolean |
1 byte | Stores true or false values |
char |
1 byte | Stores a single character/letter/number, or ASCII values |
คุณจะได้เรียนรู้เพิ่มเติมเกี่ยวกับข้อมูลแต่ละประเภทในบทต่อไป