Question:

How many times “Hi” message will be displayed when we execute the following for loop?
int i;
for(i=0;i%2==0;i++)}
printf("Hi \n");

Show Hint

In loops with conditions, pay attention to how the variables are updated and check whether the loop condition will allow more than one iteration.
Updated On: Jun 16, 2025
  • 3
  • 2
  • 1
  • 0
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

The for loop starts with \(i=0\) and checks the condition \(i % 2 == 0\), which is true for every even number. The loop increments \(i\) and checks the condition. In this case, the loop will run only once because the condition is true only when \(i=0\). The message will be printed once when \(i=0\). Thus, the answer is 1.
Was this answer helpful?
0
0