No. | Contents |
1 | 【C++】基础知识 - HelloWorld,注释,变量,常量,关键字,标识符 |
2 | 【C++】基础知识 - 数据类型,sizeof,转义字符,数据输入 |
3 | 【C++】基础知识 - 算术运算符,赋值运算符,比较运算符,逻辑运算符 |
文章目录
- 1. HelloWorld
- 2. 注释
- 3. 变量
- 4. 常量
- 5. 关键字
- 6. 标识符
1. HelloWorld
#include <iostream>
using namespace std;
int main() {
// insert code here...
cout << "hello C++!" << endl;
return 0;
}
2. 注释
//
:单行注释
/**/
:多行注释
3. 变量
语法 syntax:数据类型 变量名 = 初始值;
#include <iostream>
using namespace std;
int main() {
// insert code here...
int a = 10;
cout << "a = " << a << endl;
return 0;
}
4. 常量
语法 syntax:
- # define 宏常量:# define 常量名 常量值
- const 数据类型 常量名 = 常量值
#include <iostream>
using namespace std;
# define Day 7
int main() {
// insert code here...
cout << "一周有:" << Day << "天" << endl;
const int Month = 12;
cout << "一年有:" << Month << "月" << endl;
return 0;
}
5. 关键字
6. 标识符
- 标识符不能是关键字;
- 标识符只能由字母、数字、下划线组成;
- 第一个字符必须为字母或下划线;
- 标识符中字母区分大小写。