開發平台(Platform):
Programiz C Online Compiler
問題(Question):
如下程式碼,boolean variable flag出while迴圈就消失了,有人知道原因嗎?
餵入的資料(Input):
2 (隨便輸入的數字)
預期的正確結果(Expected Output):
2
The internal boolean variable is 1
The external boolean variable is 1
錯誤結果(Wrong Output):
2
The internal boolean variable is 1
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
#include <stdio.h>
#include <stdbool.h>
int main() {
bool flag = true;
int digit;
while (scanf("%d", &digit) != EOF) {
printf("The internal boolean variable is %d\n", flag);
}
printf("The external boolean variable is %d\n", flag);
return 0;
}
先謝謝了!