首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
若有以下程序: #include<iostream> using namespace std; int fun() {static int i=0; int s=1; s+=i; i++; r
若有以下程序: #include<iostream> using namespace std; int fun() {static int i=0; int s=1; s+=i; i++; r
admin
2019-05-06
23
问题
若有以下程序:
#include<iostream>
using namespace std;
int fun()
{static int i=0;
int s=1;
s+=i;
i++;
return s;
}
int main()
{int i,a=0;
for(i=0;i<5;i++)
a+=fun();
cout<<a<<end1;
return():
}
程序运行后,输出的结果是( )。
选项
A、20
B、24
C、25
D、15
答案
D
解析
由主函数入手,在for循环中调用fun函数,其中调用次数为5。fun中i为静态变量,有效到文件结束。第一次调用fun后为s=1,a=1;第二次调用后s=2,a=3第三次s=3,a=6;第四次s=4,a=10;第五次s=5,a=15。
转载请注明原文地址:https://jikaoti.com/ti/kvA0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
当使用关键字______作为函数返回类型时,该函数不返回任何值。
某二叉树共有60个叶子结点与50个度为1的结点,则该二叉树中的总结点数为()。
有如下程序:#include<iostream>usingnamespacestd;voidfun(int&x,inty){intt=x;x=y;y=t;}intmain(){inta[2]={
下列关于继承的描述中,错误的是()。
下列叙述中错误的是()。
软件需求规格说明书应具有完整性、无歧义性、正确性、可验证性、可修改性等特性,其中最重要的是______。
下列有关模板的叙述中,正确的是
A、 B、 C、 D、 B对二叉树的前序遍历是指:先访问根结点。然后访问左子树,最后访问右子树,并且,在访问左、右子树时。先访问根结点,再依次访问其左、右子树。
A、 B、 C、 D、 A线性表、栈、队列和双向链表都是典型的线性结构;而二叉树是典型的非线性结构。【知识拓展】什么是线性结构?有3个衡量标准:①有且只有一个根结点;②每个结点最多有一个前件(直接前驱),也
下列关于运算符重载的描述中,正确的是()。
随机试题
A.TTGACAB.TATAATC.TATAD.AATAAA真核生物Hogness盒序列是指
髁状突颈部骨折常伴有()
建设工程监理工作中,动态跟踪项目执行情况并处理好工程索赔等事宜,属于目标控制的()措施。
钢结构焊接验收时,二级焊缝不得有()等质量缺陷
阿拉瓜利河位于巴西亚马孙河流域的北部,注入大西洋,全长只有220千米,下游河道宽约2千米,且河床较浅,沿河多沼泽。在特定时间,河口会出现涌潮。浩浩荡荡的潮水从河口沿河道逆流而上60千米,时速30余千米,潮高可达2~4米。下图示意阿拉瓜利河的中下游位置。据此
学生初学英文字母时,常常将其读成汉语拼音。这属于()。
根据下列资料,回答问题。2013年全国社会物流总额197.8万亿元,同比增长9.5%,增幅比上年回落0.3个百分点。分季度看,一季度增长9.4%,上半年增长9.1%,前三季度增长9.5%。其中,工业品物流总额181.5万亿元,同比增长9.7%,增
在不同历史条件下,人们报效祖国的方式往往是不同的。不论以什么样的方式来报效祖国,都要
a.それでb.それにc.それともd.それでもe.それではA「どうして土曜日にパーティーに行かないの?」B「パーティーは嫌いです。________知っている人は誰も行かないみたいだし。」
Whathedoes,healwaysdoesitwell,thoughhehassomedifficulties.
最新回复
(
0
)