资源预览内容
第1页 / 共22页
第2页 / 共22页
第3页 / 共22页
第4页 / 共22页
第5页 / 共22页
第6页 / 共22页
第7页 / 共22页
第8页 / 共22页
第9页 / 共22页
第10页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
4.4 标识符的作用域 l标识符的作用域 1) 定义:标识符的作用域是指标识符在程序 中的可见范围。 2) 标识符的块作用域 l块:函数中用“, “括住的区域。 l一个块允许嵌套另一块。l在语法上,一个块可作为一个单语句使用 ,称为“块语句”,又称“复合语句”。 3) 标识符作用域的例子: void func(int x) int y=x+1; int y=x+2; int z=x+3; y=y*y; z=z*z; cout int year, leap, remainder; /全局参数 /year 表示年,leap 表示是否是闰年,/是闰年为1,不是闰年为0; remainder 表示year%4之结 果 void isLeap( ) /访问到三个全局变量 if(remainder=0) leap=0; else if(year%100=0) else leap=1; /访问全局变量year, remainder, leap void main() coutyear; /输入年 remainder=year%4; isLeap(); if(leap) cout int isLeap(int year) if(year%4=0) else return 0; void main() int Year; /局部变量 coutYear; if(isLeap(Year)=1) cout“nThe year “Year“ is leap year !n“; else cout“nThe year “Year“ is not leap year !n“; 上一节 返回 下一节
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号