-1

code

main( )
{
 int i ;
 for ( i = 1 ; i <= 5 ; printf ( "\n%d", i ) ) ;
     i++ ;
}

output

1 infinite times.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • The syntax is incorrect. Remove the semicolon after for. i++ is outside of the `for` body because of the ";" – Nellie Danielyan Aug 22 '20 at 18:49
  • @NellieDanielyan The syntax is correct ;-) Likely intended as a test/teaser. – P.P Aug 22 '20 at 18:59
  • @P.P you got it. It's a question in the book "Let us C" by Yashwant Kanetkar. – Shivam Singh Aug 22 '20 at 19:04
  • 1
    @ShivamSingh It's good that you mentioned your source - "Let us C" is not considered as a good book to learn C. It has numerous bugs, makes bad assumptions about implementations, etc. See [The definitive C book guide and list](https://stackoverflow.com/q/562303/1275169). – P.P Aug 22 '20 at 19:07

1 Answers1

1

You have a trailing ; at the end of the loop that effectively makes your code:

for ( i = 1 ; i <= 5 ; printf ( "\n%d", i ) )
{
}
i++;
John Kugelman
  • 349,597
  • 67
  • 533
  • 578