C ++เกมส์

C++ HOME บทนำ C++ C++ เริ่มต้นใช้งาน ไวยากรณ์ C++ เอาต์พุต C++ ความคิดเห็น C++ ตัวแปร C++ อินพุตผู้ใช้ C++ ประเภทข้อมูล C++ ตัวดำเนินการ C++ สตริง C++ C++ คณิตศาสตร์ C++ บูลีน เงื่อนไข C++ สวิตช์ C++ C ++ ในขณะที่วนรอบ C ++ สำหรับลูป C++ พัก/ดำเนินการต่อ อาร์เรย์ C++ การอ้างอิง C++ ตัวชี้ C++

ฟังก์ชัน C++

ฟังก์ชัน C++ พารามิเตอร์ฟังก์ชัน C++ ฟังก์ชัน C++ โอเวอร์โหลด

คลาส C++

C++ OOP C++ คลาส/วัตถุ วิธีการคลาส C ++ ตัวสร้าง C++ ตัวระบุการเข้าถึง C++ การห่อหุ้ม C++ มรดก C++ C++ Polymorphism ไฟล์ C++ ข้อยกเว้น C++

C++ วิธีการ

เพิ่มสองตัวเลข

ตัวอย่างภาษา C++

ตัวอย่างภาษา C++ คอมไพเลอร์ C++ แบบฝึกหัด C++ แบบทดสอบ C++


ประเภทข้อมูล 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

คุณจะได้เรียนรู้เพิ่มเติมเกี่ยวกับข้อมูลแต่ละประเภทในบทต่อไป


แบบฝึกหัด C++

ทดสอบตัวเองด้วยแบบฝึกหัด

ออกกำลังกาย:

เพิ่มชนิดข้อมูลที่ถูกต้องสำหรับตัวแปรต่อไปนี้:

 myNum = 9;
 myDoubleNum = 8.99;
 myLetter = 'A';
 myBool = false;
 myText = "Hello World";