Sunday, 15 September 2013

Why isn't this an infinite loop?

Why isn't this an infinite loop?

Why doesn't the following loop run infinite times? I expect that upon
reaching 65535, i should overflow back to zero.
#include<stdio.h>
int main()
{
short int i = 0; //(assume short int is 2 bytes)
for(i<=5 && i>=-1; ++i; i>0)
printf("%u\n", i);
return 0;
}

No comments:

Post a Comment