- 单行注释
//
- 多行注释
/* */
- 变量:给一段指定的内存空间起名,方便操作这段内存
语法:数据类型 变量名 = 初始值
示例:
#include <iostream>
using namespace std;
int main()
{
int a = 10;
cout << "a = " << a << endl;
system("pause");
return 0;
}
- 常量:用于记录程序中不可更改的数据
c++定义常量两种方式:
1 #define 宏常量:#define 常量名 常量值
通常在文件上方定义,表示一个常量。
2 const修饰的变量:const 数据类型 常量名 = 常量值
通常在变量定义前加关键字const,修饰该变量为常量,不可修改。
示例:
#include <iostream>
using namespace std;
#define Day 7
int main()
{
cout << "一周总共有" << Day << "天" << endl;
const int month = 12;
cout << "一年总共有" << month << "月" << endl;
system("pause");
return 0;
}