Các kiểu dữ liệu C ++
Các kiểu dữ liệu C ++
Như đã giải thích trong chương Biến , một biến trong C ++ phải là một kiểu dữ liệu được chỉ định:
Thí dụ
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
Các kiểu dữ liệu cơ bản
Kiểu dữ liệu chỉ định kích thước và kiểu thông tin mà biến sẽ lưu trữ:
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 |
Bạn sẽ tìm hiểu thêm về các kiểu dữ liệu riêng lẻ trong các chương tiếp theo.