第二章C++概述.ppt

第二章C++概述.ppt

说明: (1)常量也可以用变量初始化。 const 类型名 常量名=变量名; float a=3.4; const float b=a; a=4.5;coutb; 常量在其有效的范围内不能再赋值。而变量可以多次赋值。 (2)常量一旦初始化,在其作用域内都不能修改。 #includeiostream.h void f( ) {const a=100; couta; } void main( ) {float a; a=3.3; couta; f( ); } (3)常量可以作为函数参数。 int f ( const int k) { const int j=k*k; coutk; return j; } void main( ) {coutf(3);} void t(const int i) { ++i; //error } 说明: (1)函数原型的参数表中可不包含参数的名字,而只包含参数的类型,但函数头中必须给出参数的名字。 如:int cal(int ,int); int main( ) { … } int cal(int a,int b) {return a*

文档评论(0)

1亿VIP精品文档

相关文档