1、define
2、定义变量
- define 可以用把变量定义为常量,放在主函数main之前 。例如:
#define N 10 //把N定义为10,那么之后在函数中遇见N就是10。
- 变量类型 变量=常数值;
注意:变量的的首字母不能为数字,只能是字母或下划线。
int _abc_123 = 9;
cout << "_abc_123 = " << _abc_123 << " 这个数" << endl; //正确
int abc_123 = 9;
cout << "abc_123 = " << abc_123 << " 这个数" << endl; //正确
int 1abc = 9; //错误
cout << "1abc = " << 1abc << " 这个数" << endl;
随便写的代码:
#include <iostream>
using namespace std;
#define N 10
int main()
{
cout << "hello world C++" << endl;
int abc_123 = 9;
cout << "abc_123 = " << abc_123 << " 这个数" << endl;
const int a = 7; //之后a就不可以改成其他常量了;
cout << "a = " << a << endl;
system("pause");
return 0;
}