嵌入式C开发基础题(14)
来源:互联网 发布:淘宝格子铺免费推广 编辑:程序博客网 时间:2024/06/05 04:00
【重要!!!】第14题:考查静态变量的知识
#include <stdio.h>int counter (int i){static int count =0;count= count +i;return(count );}void main(){int i , j;for(i=0; i <=5; i++)j= counter(i);}
本程序执行到最后,j的值是:
(a)10(b) 15 (c) 6 (d) 7
解答:
这道题考查的是静态变量的知识,当每次调用完函数之后,静态变量的值不会丢失,这与栈中的临时局部变量明显不同的地方.
所以,第一次调用counter(0)之后,count=0
第二次调用 counter(1)后count= 0+1;
第三次调用 counter(2)count = 1+2; /* count = count +i */
第四次调用 counter(3)count = 3+3;
第五次调用 counter(4)count = 6+4;
第六次调用 counter(5)count = 10+5;
- 嵌入式C开发基础题(14)
- 嵌入式C开发基础题(1)
- 嵌入式C开发基础题(2)
- 嵌入式C开发基础题(3)
- 嵌入式C开发基础题(4)
- 嵌入式C开发基础题(5)
- 嵌入式C开发基础题(6)
- 嵌入式C开发基础题(6)
- 嵌入式C开发基础题(8)
- 嵌入式C开发基础题(9)
- 嵌入式C开发基础题(10)
- 嵌入式C开发基础题(12)
- 嵌入式C开发基础题(13)之C的变长参数
- 嵌入式C开发基础题(11)之自减操作
- 嵌入式开发学习之基础编程语言 C 语言
- 嵌入式软件开发培训笔记——c编程基础
- 嵌入式开发之c基础第一天笔记
- 嵌入式开发之c基础第二天学习笔记
- 三星 samsung odin线刷包和卡刷包的制作方法
- 心静是一门艺术
- MFC VC 中 TreeView 全面解析
- Unity Application Block 1.0系列(3): 属性/设值方法注入(Property/Setter Injection)
- EditText中的多行输入问题
- 嵌入式C开发基础题(14)
- Unity Application Block 1.0系列(4): 方法调用注入(Method Call Injection )
- hdu 4722
- 【cocos2d-x】cocos2d-x学习笔记之一
- WebLogic之Cannot parse POST parameters of request解决方法
- hduoj 4722 Good numbers
- Notepad++快捷键
- Unity Application Block 1.0系列(5): 使用BuildUp让已存在对象实例也支持依赖注入
- Linux 文件系统