ExamVeda
Login
Home
This question belongs to C Program Control Structures
Control Structures
?

What will be the output given program?
#include<stdio.h>
void main()
{
	int i = -10;
	for(;i;printf("%d ", i++));
}

Answer & Solution
Correct Answer: Option A

for loop can be initialized outside of the loop. Since until -1 value of i remain a non-zero value and hence the condition is true up to -1. But when i is further increases its value becomes 0 and condition becomes false and loop stops there.

Note:In C any non-zero value(positive or negative) evaluates to true and only zero value is evaluates to false.

Examveda
Question posted by Examveda
Community

Join the Discussion

2 Comments
Daniyal Ansari
Daniyal Ansari 6 years ago
Miss. Anjali Saroha you are wrong because it will execute and gives output
-10-9-8-7-6-5-4-3-2-1
Anjali Saroha
Anjali Saroha 9 years ago
but in this the for loop have ; at the closing
it will create compiler error