第三章 变量与常量

常量

当在类型名前面加上关键字 const 后,表示它是一个只读的量.这种变量不能修改它的值,因而称为常量.

#include<iostream>
int main()
{
    const int MAX_SIZE = 1024;
    printf("a : %d \n",MAX_SIZE);    // 读取 const 常量的值
    int b = MAX_SIZE;                // 将 MAX_SIZE 的值赋值给变量 b
    printf("b:%d \n",b);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/QLEO/p/9585015.html
今日推荐