常类型是指使用类型修饰符const说明的类型,常类型的变量或对象的值是不能被更新的。
#include<iostream>
using namespace std;
int main(){
const int b = 10;
b = 0; //error ,不能对const 变量进行更新

const string s = "helloworld";
const int i,j=0;
}
上述有两个错误,第一:b为常量,不可更改!第二:i为常量,必须进行初始化!(因为常量在定义后就不能被修改,所以定义时必须初始化。)
#include<iostream>
using namespace std;
int main(){
const int b = 10;
//b = 0; //error ,不能对const 变量进行更新

const string s = "helloworld";
const int i=20;
const int j=30;

cout<<"OK" <<endl;
}