> For the complete documentation index, see [llms.txt](https://docs.1l.lol/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.1l.lol/basics/data-types.md).

# 基本数据类型

### 四种基本类型

| 类型    | 关键字         | 说明                | 例子                    |
| ----- | ----------- | ----------------- | --------------------- |
| 整型    | `int`       | 整数，约 ±21 亿        | `int a = 10;`         |
| 长整型   | `long long` | 更大范围的整数           | `long long b = 1e18;` |
| 单精度实型 | `float`     | 小数，约 6\~7 位有效数字   | `float f = 3.14f;`    |
| 双精度实型 | `double`    | 小数，约 15\~16 位有效数字 | `double d = 3.14159;` |
| 字符型   | `char`      | 单个字符，用单引号         | `char c = 'A';`       |
| 布尔型   | `bool`      | true / false      | `bool ok = true;`     |

### 取值范围（常见）

| 类型           | 范围                        |
| ------------ | ------------------------- |
| int          | -2147483648 \~ 2147483647 |
| unsigned int | 0 \~ 4294967295           |
| long long    | ≈ -9.2×10¹⁸ \~ 9.2×10¹⁸   |
| char         | -128 \~ 127               |

### 使用注意

* 数据超过 int 范围会溢出，应改用 `long long`。
* 小数尽量用 `double`，精度更高。
* 字符用**单引号** `'A'`，字符串用**双引号** `"A"`。

```cpp
#include <iostream>
using namespace std;

int main() {
    int i = 100;
    long long big = 1234567890123LL;
    double pi = 3.1415926;
    char grade = 'A';
    bool pass = true;
    cout << i << " " << big << " " << pi << " "
         << grade << " " << pass << endl;  // bool 输出 1
    return 0;
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.1l.lol/basics/data-types.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
