0

Help me with this Output.

int main() { int sub[50], i ; for ( i = 0 ; i <= 48 ; i++ ) ; { sub[i] = i; printf ( "\n%d", sub[i] ) ; } } output is 49

18th Jul 2020, 5:57 AM
Sri pranavi Donapati
Sri pranavi Donapati - avatar
4 Antworten
+ 3
Sri pranavi Donapati It will give error because there is semicolon (;) after for loop. If you remove semicolon then output will be 0 to 48 not only 49
18th Jul 2020, 6:57 AM
A͢J
A͢J - avatar
+ 3
Sri pranavi Donapati Why there would be garbage value if there is already sub declared with size of 50. And if you see the program you are actually printing the value of i. Just run the program in Sololearn Playground and see what happens.
18th Jul 2020, 4:40 PM
A͢J
A͢J - avatar
0
Remove the semicolon after the for loop , int main() { int sub[50], i ; for ( i = 0 ; i <= 48 ; i++ ) { sub[i] = i; printf ( "\n%d", sub[i] ) ; } }
18th Jul 2020, 8:13 AM
Chathu
0
AJ Anant #G3 why can't that error only be 49 ,why can't it be any garbage value?
18th Jul 2020, 1:19 PM
Sri pranavi Donapati
Sri pranavi Donapati - avatar