これは静的変数を学習していた場所のコードです。whileループと静的変数
#include <stdio.h>
/* function declaration */
void func(void);
static int count = 5; /* global variable */
main() {
while(count--) {
func();
}
return 0;
}
/* function definition */
void func(void) {
static int i = 5; /* local static variable */
i++;
printf("i is %d and count is %d\n", i, count);
}
私がコンパイルされ、端末上でこれを実行し、この出力を得た
i is 6 and count is 4
i is 7 and count is 3
i is 8 and count is 2
i is 9 and count is 1
i is 10 and count is 0
count
の値が0
に等しいとき、ループが停止しなかった理由私のクエリがありますか?なぜそれが負の無限大に向かっていないのですか?
「while(0)」は何をしているのでしょうか? – juanchopanza
http://en.cppreference.com/w/cpp/language/while – SingerOfTheFall
'while'ループの定義を探します。条件が「偽」または「0」になるまで続きます。 – Gravell