首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
若有以下程序: #include<stdio.h> int f(int m) { static int n=0; int a = 2; n+ +;a+ +; return n+m+a; } main( ) { int k; for(k=0;k<4;k+ +
若有以下程序: #include<stdio.h> int f(int m) { static int n=0; int a = 2; n+ +;a+ +; return n+m+a; } main( ) { int k; for(k=0;k<4;k+ +
admin
2019-04-14
39
问题
若有以下程序:
#include<stdio.h>
int f(int m)
{
static int n=0;
int a = 2;
n+ +;a+ +;
return n+m+a;
}
main( )
{
int k;
for(k=0;k<4;k+ +)
printf(″%d,″,f(k));
}
则程序的输出结果是( )。
选项
A、3,5,7,9,
B、4,7,10,13,
C、4,5,6,7,
D、4,6,8,10,
答案
D
解析
本题考查静态局部变量以及自增运算符,静态局部变量在函数调用结束后,并不释放,仍然保留它的值。本题中,k为0时,returnn+m+a之前,n为1,a为局部变量是3,m为0,所以第一个返回值为4。k为1时,在函数返回值之前,静态局部变量为2,局部变量a仍然为3,m为1,所以结果是6。以此类推,答案为D。
转载请注明原文地址:https://kaotiyun.com/show/g9Rp777K
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
以下程序段给数组所有的元素输入数据,请选择正确答案填入。#include<stdio.h>main(){inta[10]=0;while(i<10)scan("%d
下列叙述中错误的是()。
下列程序段的输出结果是【】。intn=’c’;switch(n++){default:printf("error");break;case’a’:case’A’:case’b’:
数据模型包括数据结构、()和数据条件。
有以下程序#include#includeStructA{inta;charb[10];doublec;};structAf(structAt);main(){stru
在C语言程序中,下列说法正确的是()。
在先左后右的原则下,根据访问根结点的次序,二叉树的遍历可以分为三种:前序遍历、【】遍历和后序遍历。
若有说明:inta[][3]={0,0};则不正确的叙述是()。
若有如下说明,且int类型占两个字节,则正确的叙述为()。structst{inta;intb[2];}a;
下面选项中合法的字符常量是()。
随机试题
某省天洋市滨海区一石油企业位于海边的油库爆炸,泄漏的石油严重污染了近海生态环境。下列哪一主体有权提起公益诉讼(其中所列组织均专门从事环境保护公益活动连续5年以上且无违法记录)?
Somepeoplethinkthatanimalresearchisirrelevant______ourhealthandthatitcanoftenproducemisleadingresults.
______不是Windows自带的应用程序。
在Internet中,电子公告板的缩写是()。
以下属于工频机主电路的是
蒿芩清胆汤与橘皮竹茹汤二方均有的功用是
甲公司销售一批货物给乙公司,货已发出,货款为10000元,增值税额为1700元,按合同规定3个月以后付款,乙公司交给甲公司一张3个月到期的商业承兑汇票,票面金额为11700元。此时,甲公司应确认的应收票据金额为()元。
ThefactthatmostAmericansliveinurbanareasdoesnotmeanthattheyresideinthecenteroflargecities.Infact,moreAme
Mysistersaidthathernewboyfriendwasthelivingend.Theunderlinedpartmeans________.
Adultsaregettingsmarteraboutbowsmartbabiesare.Notlongago,researcherslearnedthat4-day-oldscouldunderstand【B1】__
最新回复
(
0
)