在C程序中,对于如下的两个for语句,其运行后a和b的值分别为( )。
for(int a=0;a==0;a++);
for(int b=0;b=0;++b);
- A.0,0
- B.0,1
- C.1,0
- D.1,1
正确答案及解析
正确答案
解析
for循环语法:
for(①初始化表达式;②条件表达式;④累加器){
③循环体
}
执行流程:
(1)执行初始化表达式①;
(2)执行条件表达式②,如果条件满足,为true,执行循环体③, 执行累加器④,继续执行条件表达式②,如果条件满足,为 true,执行循环体③, 执行累加器④……以此类推,直到循环条件不满足,结束循环
本题中第一个for循环语句,第一次运行时先执行赋值语句a=0,然后进行条件比较a==0为真,然后执行循环题(本题循环体为空),再执行累计部分即a++;执行后a=1;再进行条件比较a==0为假,最后结束循环。所以这时a的值为1;
本题中第二个for循环语句,第一次运行时先执行赋值语句b=0,然后进行条件比较b=0为假(b=0是一个赋值语句不是一个条件表达式,判定结果为0即假),接下来就直接结束循环;所以这时b的值为0。
包含此试题的试卷
你可能感兴趣的试题
Advancements in ( )have contributed to the growth of the automotive industry through the creation and evolution of self-driving vehicles.
-
- A.Artificial Intelligence
- B.Cloud Computing
- C.Internet of Things
- D.Big Data
- 查看答案
In project human resource management , ( )is not a source of power for the project manager.
-
- A.referent power
- B.expert power
- C.reward power
- D.audit power
- 查看答案
At the project establishment stage , the feasibility study mainly includes techinical feasibility analysis , ( ), operation environment feasibility analysis and other aspects of feasibility analysis.
-
- A.detail feasibility analysis
- B.opportunity analysis
- C.economic feasibility analysis
- D.risk analysis
- 查看答案
( )is a grid that shows the project resources assigned to each work package.
-
- A.Stakeholder engagement assessment matrix
- B.Requirements traceability matrix
- C.Probability and impact matrix
- D.Responsibility assignment matrix
- 查看答案
Xinhua News Agency reported in January 2022,Chian will further promote the developmet of a digital economy during the 14th Five-Year Plan eriod(2021-2025). The plan also emphasized industrial ( )transformation.
-
- A.digital
- B.networking
- C.intelligentize
- D.informatization
- 查看答案