#include #include void main() { int i = 5; for(;scanf(“%d”, &i); printf(“%d”, i)); getch(); } In the following program how long will the for loop get executed?

#include

#include

void main()

{

int i = 5;

for(;scanf(“%d”, &i); printf(“%d”, i));

getch();

}

In the following program how long will the for loop get executed?

A. The for loop would not get executed at all

B. The for loop would get executed only once

C.  The for loop would get executed 5 times

D. The for loop would get executed infinite times

Hướng dẫn

Chọn D là đáp án đúng

Xem lời giải

Xem lời giải

Hàm scanf() đợi người dùng nhập giá trị vào từ bàn phím. Đồng thời trong đoạn code này, hàm scanf() luôn trả về 1 (vòng lặp vô hạn), hàm printf() in ra giá trị nhập vào.

 

Thư viện tài liệu12 Tháng bảy, 2023 @ 2:58 chiều

Đánh giá chủ đề này