Actually I meant "output* of this program?How?"Code:main() { int i; for(i=1;i<=5;printf("\n%d",i)); i++; }
Why am I getting an indefinite loop of 1?
Actually I meant "output* of this program?How?"Code:main() { int i; for(i=1;i<=5;printf("\n%d",i)); i++; }
Why am I getting an indefinite loop of 1?
Last edited by sameertelkar; 09-15-2012 at 03:58 AM.
Notice the semi-colon at the end of the for loop. As such, your for loop has an empty body.
Oh, and you should explicitly declare main as returning an int.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Because of the extra semi-colon your program is the same as
The for loop never ends: it's an infinite loop.Code:main() { int i; for(i=1;i<=5;printf("\n%d",i)) { /* do nothing */ } i++; }
Thank you to you both.I think I got it.