I think it because the compiler put the value on the Data Segment/DS
side by side.
so no matter how big your value are, it'll put all the value into DS.


--- In [email protected], debasish deka <[EMAIL PROTECTED]> wrote:
>
> Hello All,
> A few days back I attended Huawei Interview where the following
code's output was expected:
>     unsigned char i;
>     for(i=0;i<2000;i++)
>          printf("\t%d",i);
> A simple thinking gives the output to be : 
> values from 0 to 255.
> When I checked it out on my Dev-C++ it showed counting exactly up to
2000.
> Now my doubt it if a character variable occupies one byte then it
should count upto 255 only then it should overflow. Thus the result
should be either counting upto 255(and stop) or ending in an infinite
loop counting each time up to 255. Then why and how it is counting
uoto 2000 (exactly).
> Again in a forum it was asked to give the output of the following
codes ::
>     unsigned i;
>     i=100*400;
>     printf("\n%d\n",i);
> Strangely again, the output was exactly 40000as opposed to + 32767
or showing any sort or overflow, since the range of unsigned int
ranges from- 32767 to 32768.
> Now my question is how the compiler manages to tackle such
situations, I mean what mechanism does the compiler the aplies in such
a situation...
> Regards,
> Debasish
> 
>  
> Karmennevaya Dhikaraste, Maaphaaleshu Kadaachanah
> 
> 
> 
> 
> 
>       Now you can chat without downloading messenger. Go to
http://in.messenger.yahoo.com/webmessengerpromo.php
> 
> [Non-text portions of this message have been removed]
>


Reply via email to