0

The result of this code is 65535 But I believe that for && both sides must hold true (rather one side being true is enough for ||) so how come the result is 65535 ????? when after 5++ the first condition becomes false ????? Thanks in advance

#include<stdio.h>
#include<conio.h>

void main()
{
 short int i=0;
 clrscr();

 for(i<=5&&i>=-1;++i;i>0)
 printf("%u",i);
 getch();
}
2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by ram619
1

The for loop is completely nonsensical. It's like this:

for (initialization; condition; increment)
{
    body
}

Where the roughly analogous while loop is:

initialization

while (condition)
{
    body
    increment
}

So your loop, for(i<=5&&i>=-1;++i;i>0) printf("%u",i); would look something like this while loop:

i <= 5 && i >= 1;

while (++i)
{
    printf("%u", i);
    i > 0;
}

Doesn't make much sense, does it?

0

Thanks deceptikon got it now......... the && is just initialization.
:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.