c语言const 变量使用注意点

来源:互联网 发布:阿里巴巴一键上传淘宝 编辑:程序博客网 时间:2024/05/16 11:37

const修饰的变量被许多人错误的认为是常量,但是const所修饰的变量应该是只读变量,所以const修饰的变量它还是一个变量。

在switch case中的一个case分支中如果用const变量来表达,则会报出错误:error: case label does not reduce to an integer constant

const int b=2;int a = 1;switch(a){    case 1:                   break;    case b:                   break;    default:                   break;}

编译运行会报错:error: case label does not reduce to an integer constant

原创粉丝点击