What will be the output given program?
#include<stdio.h>
void main()
{
int i = -10;
for(;i;printf("%d ", i++));
}
#include<stdio.h>
void main()
{
int i = -10;
for(;i;printf("%d ", i++));
}
A. -10 to -1
B. -10 to infinite
C. -10 to 0
D. Complier error
Answer: Option A
Solution(By Examveda Team)
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.
Join The Discussion
Comments ( 2 )
Which control structure is used to repeatedly execute a block of code in C?
A. for loop
B. if statement
C. switch case
D. while loop
In C, what is the purpose of the 'break' statement within a loop?
A. Continue to the next iteration
B. Exit the program
C. Terminate the loop and exit it
D. Skip the current iteration
What is the purpose of the 'else' statement in C's 'if-else' control structure?
A. Execute the 'if' block
B. Execute the 'else' block
C. Execute both 'if' and 'else' blocks
D. Skip the 'if' block
Which control structure is used to make a decision between two or more alternatives in C?
A. switch case
B. for loop
C. if statement
D. while loop
Miss. Anjali Saroha you are wrong because it will execute and gives output
-10-9-8-7-6-5-4-3-2-1
but in this the for loop have ; at the closing
it will create compiler error