AMU 2025 Computer PYQ — In the following program, how many times 'for' loop will be execu… | Mathem Solvex | Mathem Solvex
Tip:A–D to answerE for explanationV for videoS to reveal answer
AMU 2025 — Computer PYQ
AMU | Computer | 2025
In the following program, how many times 'for' loop will be executed? #include<stdio.h> void main() { int i=5; for (;;;) printf ("%d", i); }
Choose the correct answer:
A.
59 times
B.
10 times
C.
Infinite times
(Correct Answer)
D.
20 times
Correct Answer:
Infinite times
Explanation
The for loop in the provided program will execute an infinite number of times
Here is the breakdown of why:
The general syntax of a for loop in C is for (initialization; condition; update).
In C programming, if the condition expression (the middle part) is omitted, it is implicitly considered to be always true (a non-zero constant).
The loop body consists of the statement immediately following the for loop: printf ("%d", i);. This statement prints the value of i (which is 5) repeatedly.
Since there is no condition that ever evaluates to false and no break or return statement within the loop body to terminate it, the loop continues to run indefinitely until the program is manually stopped (e.g., by pressing Ctrl+C in a terminal).
Explanation
The for loop in the provided program will execute an infinite number of times
Here is the breakdown of why:
The general syntax of a for loop in C is for (initialization; condition; update).
In C programming, if the condition expression (the middle part) is omitted, it is implicitly considered to be always true (a non-zero constant).
The loop body consists of the statement immediately following the for loop: printf ("%d", i);. This statement prints the value of i (which is 5) repeatedly.
Since there is no condition that ever evaluates to false and no break or return statement within the loop body to terminate it, the loop continues to run indefinitely until the program is manually stopped (e.g., by pressing Ctrl+C in a terminal).