> 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/operators.md).

# 基本运算

### 算术运算

| 运算 | 符号  | 说明           |
| -- | --- | ------------ |
| 加  | `+` |              |
| 减  | `-` |              |
| 乘  | `*` |              |
| 除  | `/` | 两整数相除为**整除** |
| 取余 | `%` | 只能用于整数       |

```cpp
int a = 7, b = 2;
cout << a / b << endl;   // 3（整除）
cout << a % b << endl;   // 1（余数）
cout << 7 / 2.0 << endl; // 3.5
```

取余常用于判断整除、提取数位：`x % 10` 取个位，`x / 10` 去掉个位。

### 关系运算

`> >= < <= == !=`，结果是 `bool`（true/false）。

> 注意区分赋值 `=` 与判断相等 `==`。

### 逻辑运算

| 运算 | 符号     | 说明      |
| -- | ------ | ------- |
| 与  | `&&`   | 两边都真才真  |
| 或  | `\|\|` | 只要一边真就真 |
| 非  | `!`    | 真变假、假变真 |

短路求值：`a && b` 中若 a 为假，则不再判断 b。

### 自增自减

```cpp
int x = 5;
cout << x++ << endl; // 输出 5，然后 x 变 6（后置）
cout << ++x << endl; // 先 x 变 7，输出 7（前置）
```

### 复合赋值

`+=`、`-=`、`*=`、`/=`、`%=`，如 `a += 3` 等价于 `a = a + 3`。


---

# 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/operators.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.
