首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序: #include int f(int n); main( ) {int a=3,s; S=f(a);s=s+f(a);printf("%d\n",s); } int f(int n)
有以下程序: #include int f(int n); main( ) {int a=3,s; S=f(a);s=s+f(a);printf("%d\n",s); } int f(int n)
admin
2021-07-09
21
问题
有以下程序:
#include
int f(int n);
main( )
{int a=3,s;
S=f(a);s=s+f(a);printf("%d\n",s);
}
int f(int n)
{ static int a=1;
n+=a++;
return n;
}
程序运行后的输出结果是( )。
选项
A、9
B、8
C、7
D、10
答案
A
解析
题目中的静态局部变量a,在静态存储区内分配存储单元,在程序整个运行期间都不释放。所以第一次调用函数执行n+=a++;时a先与n相加在再进行自增。n的值为4,a的值为2,且a变量执行完后空间没有释放。再执行s=s+f(a)时,s的值为4,调用f(a)函数时n的返回值为n=3+2=5,此时a的值为3。所以s的值为9。
转载请注明原文地址:https://kaotiyun.com/show/ZEkp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
以下叙述中正确的是
以下叙述中错误的是
若变量已正确定义为int型,要通过语句:scanf("%d,%d,%d",&a,&b,&c);给a赋值1、给b赋值2、给c赋值3,以下输入形式中错误的是()。(注:□代表一个空格符)
下列关丁二叉树的叙述中,正确的是()。
下面关于数据库三级模式结构的叙述中,正确的是()。
关于位运算的叙述中正确的是()。
在关系数据库中,用来表示实体间联系的是
下面不属于黑盒测试方法的是
数据字典(DD)所定义的对象都包含于()。
下面属于白盒测试方法的是()。
随机试题
简述储存的基本目标
癫、狂病位在心,与其发病关系密切的脏腑有
在哺乳动物体内氨的主要去路是合成尿素排出体外。尿素是肝脏中由尿素循环中一系列酶催化形成的。合成的尿素被排泄进入血流,再被肾脏分离,从尿中排出。尿素生成的循环反应过程可概括为1932年,H.Krebs和他的学生K.Henseleit根据一系列实验首次提出
房地产投资项目的利润与利润分配表主要用于计算投资项目的()。
()是所有权中带有根本性的一项权能。
()是构成词义的最小意义单位,又叫词的语义成分或语义特征。
从数据库管理系统的角度看,数据库系统一般采用三级模式结构,如下图所示。图中①、②处应填写(28),③处应填写(29)。
In the following essay, each blank has four choices. Choose the most suitable one from the four choices and write down in the an
设有两个数据库表,父表和子表之间是一对多的联系,为控制父表和子表中数据的一致性,可以设置“参照完整性规则”,要求这个表()。
Theboycaughtfive______yesterday.
最新回复
(
0
)