doc/docs/CPlusPlus-main/07_C++的标识符.md
sairate fa9377e4ae docs(book): 添加现代 C++教程及相关代码
- 新增现代 C++ 教程的 Preface 章节,包括英文和中文版本
- 添加 C++ Primer 练习代码
- 新增 Learn C++ 教程的 C++ 开发简介章节
- 添加头文件解析文档
- 更新 mkdocs.yml,包含新教程的目录结构
- 修改项目设置,使用 Python 3.10环境
2025-07-08 09:52:45 +08:00

54 lines
1.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# C++的标识符
# 1. 标识符
① 标识符就是 C++ 给变量、常量的命名。
② 标识符有一套自己的命名规则:
1. 标识符不能使关键字。
2. 标识符只能由字母、数字、下划线组成。
3. 第一个字符必须为字母或下划线。
4. 标识符中字母区分大小写。
③ 建议:给标识符命名时,争取做到见名知意,方便自己和他人的阅读。
```python
#include <iostream>
using namespace std;
int main()
{
//1标识符不可以是关键字
//int int = 10; //报错
//2标识符由字母数字下划线构成
int abc = 10;
int _abc = 20;
int _123abc = 40;
//3标识符第一个字符只能是字母或下划线
//int 123abc = 50; //报错
//4标识符区分大小写
int aaa = 100;
//cout << AAA << endl; //报错AAA和aaa不是同一个名称
//建议给变量起名的时候最好能够做到见名知意
int num1 = 10;
int num2 = 20;
int sum = num1 + num2; //建议用num1num2sum表示加法而不是用abc来表示
cout << sum << endl;
system("pause");
return 0;
}
```
运行结果:
- 30
- 请按任意键继续. . .