以下代码片段打印“hello”多少次? [英] How many times will the following code fragment print “hello”?
问题描述
for(i = 2; i< 100; i = i * i)printf(hello);
我尝试过:
for(i = 2; i< 100; i = i * i)printf(hello);
Quote:以下代码片段打印hello多少次?
我会说3次,但我错了。
for (i = 2 ; i< 100 ; i = i * i){
printf( hello);
}
第一次迭代:i = 2,i< 100 - > 你好
第二次迭代:i = 4,i< 100 - > 你好
第3次迭代:i = 16,i< 100 - > 你好
第4次迭代:i = 256,i> = 100 - >循环退出
C中有很多关于循环的资源,你最喜欢的搜索引擎会告诉你比我复制粘贴的速度快得多。
for (i = 2; i<100; i = i*i) printf("hello");
What I have tried:
for (i = 2; i<100; i = i*i) printf("hello");
Quote:How many times will the following code fragment print "hello"?
I would say 3 times, but I can be wrong.
for (i = 2; i < 100; i = i * i) { printf("hello"); }
1st iteration: i = 2, i < 100 -> "hello"
2nd iteration: i = 4, i < 100 -> "hello"
3rd iteration: i = 16, i < 100 -> "hello"
4th iteration: i = 256, i >= 100 -> loop-exit
There are a lot of resources about loops in C, your favorite search engine will tell you where much faster than I could copy-paste.
这篇关于以下代码片段打印“hello”多少次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!