定义常量
在 C++ 中,有两种简单的定义常量的方式:
- 使用 #define 预处理器。
- 使用 const 关键字。
第一种#define定义
#include <iostream>
using namespace std;
#define PI 3.14; /*#define 定义*/
int main()
{
float p=PI;
cout <<p<< endl;
return 0;
}
第二种const定义
#include <iostream>
using namespace std;
int main()
{
const float PI=3.14; /*const定义*/
cout <<PI<< endl;
return 0;
}