Thursday, April 17, 2008

Simple but Tricky :-)

Does the following run for infinity or finite time;

for (uint I = 1 ; I >-1 ; I ++);

Reason your answer


Submitted by Imran Younus

5 comments:

asifrajwana said...

its infinite. reason Uint (unsigned) always +ve.

Anonymous said...

the loop would be run finite time as the datatype of I is unsigned int so comparison would also be unsigned. the loop will run for the maximum integer value that could be stored in int datatype.

Anonymous said...

There is an error in the comparision expression of the loop.Uint is used for positive integer and -1 is the negative value.This will not run.

Anonymous said...

There is an error in the comparision expression of the FOR loop.Since UInt is used for positive integers only,it can't be used for negative number comparision.
The loop will not run.

Anonymous said...

because unsigned int dont have -1 so it runs forever...

So its an infinite loop. :)