正如中所解释的变量章节中,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 |
---|---|---|
boolean |
1 byte | Stores true or false values |
char |
1 byte | Stores a single character/letter/number, or ASCII values |
int |
2 or 4 bytes | Stores whole numbers, without decimals |
float |
4 bytes | Stores fractional numbers, containing one or more decimals. Sufficient for storing 6-7 decimal digits |
double |
8 bytes | Stores fractional numbers, containing one or more decimals. Sufficient for storing 15 decimal digits |
您将在接下来的章节中了解有关各个数据类型的更多信息。
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!