C Programming :: Basic Concepts - Discussion
2 / 90
#include<stdio.h>
void main(){
int i;
for(i=0;i<5;i++){
int x=0;
printf("%d",x);
x++;
}
}
#include<stdio.h>
void main(){
int i;
for(i=0;i<5;i++){
int x=0;
printf("%d",x);
x++;
}
}
A1234
B1234
C0
DInfinite loop
ECompilation error
Show Explanation
Each time when the control enters the loop, x becomes equal to 0, and everytime 0 gets printed. Eventhough, in line 7 the value of x gets incremented by 1, but that's of no use because each time when the control enters the loop, value of x gets re-initializied to 0.
Therefore, the correct output will be 00000.
Asked In ::
The for loop runs for i=0 to i<5, i.e, for 5 times.
Each time when the control enters the loop, x becomes equal to 0, and everytime 0 gets printed. Eventhough, in line 7 the value of x gets incremented by 1, but that's of no use because each time when the control enters the loop, value of x gets re-initializied to 0.
Therefore, the correct output will be 00000.
Read Full Answer
Report Error
Please Login First Click Here