C++ 常量

C++ 常量
常量是固定值,在程序执行期间不会改变。这些固定的值,又叫做字面量。

常量可以是任何的基本数据类型,可分为整型数字、浮点数字、字符、字符串和布尔值。

常量就像是常规的变量,只不过常量的值在定义后不能进行修改。

 

 1 #include <iostream>
 2 
 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
 4 using namespace std; 
 5 int main(int argc, char** argv) {
 6     int i=1,sum=0;
 7     while(i<=100){
 8         sum=sum+i;
 9         i++;
10     }
11     cout <<"sum="<< sum<<endl;
12     return 0;
13 }

 

posted @ 2018-08-01 14:09  borter  阅读(130)  评论(0编辑  收藏  举报