#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
How to whitelist website on AdBlocker?

How to whitelist website on AdBlocker?

  1. 1 Click on the AdBlock Plus icon on the top right corner of your browser
  2. 2 Click on "Enabled on this site" from the AdBlock Plus option
  3. 3 Refresh the page and start browsing the site