On Sunday 23 March 2008 08:45:44 titli_juit wrote:
> unsigned int i=10;
> while(i>=0)
> {
> printf("Hi");
> i--;
> }
>
> why the result is an infinite loop??Hi. It's really simple. You have an unsigned int, means no negative numbers. So lets see what will be the value of i. 10 9 8 7 6 5 4 3 2 1 0 And now the while looks at the value which is >=0, which means another iteration. When you substract 1 from a 0 value unsigned integer you get the maximum value that an int has on your system (for example if integer is 16 bits it's around 65k) which is again >=0 and the wile loop goes for another iteration, and again until it reaches 0, in which case the upper procedure repeats. regards mmlado
