ในบทช่วยสอนนี้ เราจะอภิปรายโปรแกรมเพื่อเข้าใจ integer literal ใน C/C++ (Prefixes และ suffixes)
Integer literals คือ literals สำหรับค่า integer ที่แสดงโดยตรงใน source code แบ่งเป็น 2 ประเภท −
Prefixes − Prefixes บอก base ของค่า เช่น 0x10 แสดง hexadecimal ด้วย 0x
Suffixes − Suffixes บอก type ของค่า เช่น 8465484156155LL แสดง long long integer
ตัวอย่าง
#include <iostream>
using namespace std;
int main(){
//prefixes
cout << 213 << '\n'
<< 0213 << '\n'
<< 0x213A << '\n'
<< 0b101 << '\n'
//suffixes
<< 1234567890123456789LL << '\n'
<< 12345678901234567890ull << '\n'
<< 12345678901234567890u;
return 0;
}
ผลลัพธ์
213 139 8506 5 1234567890123456789 12345678901234567890 12345678901234567890