#include2、注释using namespace std; int main() { cout << "helloworld" << endl; //关键句 system("pause"); return 0; }
多放在代码前或代码同行;
单行注释 :
//单行注释
多行注释:
3、变量与常量
变量存在的意义:方便管理内存空间
变量创建的语法:数据类型 变量名=变量初始值;
int a =10 ;
#includeusing namespace std; int main() { int a = 10; cout << "a=" << a << endl; system("pause"); return 0; }
常量
作用:用于记录程序中不可更改的数据
C++定义常量的两种方式:
1、#define 宏常量 #define 常量名 常量值
通常在文件上方定义,表示一个常量
2、const修饰的变量 const 数据类型 常量名=常量值
通常在变量定义前加关键字const,修饰该变量为常量,不可修改
常量一旦修改就会报错
#includeusing namespace std; #define day 7 int main() { const int month = 12; cout << "一周总共有" << day <<"天" <



