Replies
Welcome, guest
Join CrazyEngineers to reply, ask questions, and participate in conversations.
CrazyEngineers powered by Jatra Community Platform
-
@radha-BTDzli • Sep 3, 2014
this because the compiler automatically makes a turn-around ,i.e after it stops on a particular maximum limit of positive range,it again begins from the lowermost point.i.e
for(i=1;;i++)
{
printf("%d",i);
}
so actually this is an infinte loop as value of int ranges from -32,768 to +32,767 ,so after it reaches the maximum,again it carries on with minimum value,hope u are clear -
@anksingla-ttYJbX • Sep 3, 2014
thanks radha..
will it work same for the minimum value... -
@anksingla-ttYJbX • Sep 3, 2014
thanks radha..
will it work same for the minimum value... -
@radha-BTDzli • Sep 3, 2014
radha gogiathis because the compiler automatically makes a turn-around ,i.e after it stops on a particular maximum limit of positive range,it again begins from the lowermost point.i.e
for(i=1;;i++)
{
printf("%d",i);
}
so actually this is an infinte loop as value of int ranges from -32,768 to +32,767 ,so after it reaches the maximum,again it carries on with minimum value,hope u are clear
yes u can continue ur loop starting from minimum or from maximum,it always goes in a chainanksinglathanks radha..
will it work same for the minimum value... -
@pratap-singh-6xlmve • Sep 15, 2014
Basically the decimal numbers present in the source code are internally converted to their binary equivalents(since a computer is a digital machine and can understand 1s and 0s only) before they are processed.
During the processing, the binary sequences are incremented or decremented depending upon the logic implemented and if there occurs an overflow operation, this situation is dealt as per the binary laws. These laws may result in certain binary sequences whose decimal equivalents are negative numbers.
When the program displays the output, it displays the decimal equivalent of the changed binary sequence(that is representing a negative number). In other words we get a negative number as output.
For more information on this topic, try to learn binary addition and subtraction in the presence of overflow. The same concepts applies here.