C++学习1——常量
2021-11-22 本文已影响0人
生信小书童
#include <iostream>
using namespace std;
//常量的作用:用于记录程序中不可更改的数据
//C++ 定义常量的两种方式:
//1 #define 宏常量:#define 常量名 常量值
// 通常在文件的上方定义,表示一个常量
//2 const 修饰变量: const 数据类型 常量名 = 常量值
// 通常在变量定义前加关键字const,修饰该变量为常量,不可修改
#define Day 7
int main()
{
cout << "一周总共有" << Day << " 天" << endl;
// Day = 9; 修改常量会出错
const int mounth = 12;
cout << "一年有" << mounth << " 月" << endl;
//mounth = 14;修改常量会出错
system("pause");
return 0;
}