doc/docs/CPlusPlus-main/06_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

57 lines
869 B
Markdown
Raw 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.1 int关键字
```python
#include <iostream>
using namespace std;
int main()
{
// int int = 10; // 错误第二个int是关键字不可以作为变量的名称
system("pause");
return 0;
}
```
运行结果:
- 请按任意键继续. . .
## 1.2 sizeof关键字
① sizeof关键字可以统计数据类型所占内存大小。
② sizeof关键字语法sizeof ( 数据类型 / 变量 )
```python
#include <iostream>
using namespace std;
int main()
{
cout << "short 类型所占内存空间为:" << sizeof(short) << endl;
system("pause");
return 0;
}
```
运行结果:
- short 类型所占内存空间为2
- 请按任意键继续. . .