Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม C

ความจำเป็นของ Long Data Type ใน C

C มี Integer Types 4 แบบ: short, int, long, long long ขนาดแตกต่างตาม Architecture/Compiler

ตัวอย่างขนาด

Size of int: 4 Bytes
Size of long: 4 Bytes (Windows 64-bit) / 8 Bytes (Linux 64-bit)
Size of long long: 8 Bytes

เหตุผลทางฮาร์ดแวร์

  • CPU เรียกข้อมูลจาก RAM ผ่าน Memory Address Register (MAR)
  • ขนาด Data Bus กำหนดขนาด CPU Register (32-bit = 4 bytes ต่อ Cycle)
  • ข้อมูลใหญ่กว่า Register ต้องใช้หลาย Cycle
  • long ให้ความยืดหยุ่นสำหรับข้อมูลขนาดใหญ่บน Architecture ต่างๆ