Does the following run for infinity or finite time;
for (uint I = 1 ; I >-1 ; I ++);
Reason your answer
Submitted by Imran Younus
Subscribe to:
Post Comments (Atom)
insights from trg techies into our technology and culture
playing mind games
(of the intelligent kind)
5 comments:
its infinite. reason Uint (unsigned) always +ve.
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.
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.
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.
because unsigned int dont have -1 so it runs forever...
So its an infinite loop. :)
Post a Comment