"manishpchawda" <manishpcha...@...> wrote:
>
> [mod-- This gets discussed ad-nauseum. The behaviour is undefined
> since the code modifies x (and y) twice between sequence points.
> <http://c-faq.com/expr/seqpoints.html> --mod PN]
> 
> Hi,
> 
> I am not able to understand the output of:
> 
> unsigned char x;
> x = 300;
> printf("%d",x);

If unsigned char has the range 0..255, then, being an unsigned
type, 300 will be converted modulo 256, thus resulting in 44
(if my maths is correct.)

> int x,y;
> x = 5;
> y = 10;
> printf("%d\t%d\t%d\t%d\t",x++,y++,++x,++y);

The behaviour of this code is undefined. As such it may not
even compile. Whatever output you get on one system is
worthless since it is not guaranteed to be reproducable
on any other system, or even the same system on a different
day.

Note: compilers are not required to work out arguments to
functions (like printf) in left to right, or right to left,
or evens first, odds seconds second, or random order. Quite
simply, the order of evaluation of arguments and their
subexpressions is unspecified. Since there is no guarantee
that x++ will be evaluated before or after ++x, the code
modifies x twice between two sequence points. The C
language does not guarantee a behaviour (let alone a value)
when that happens.

-- 
Peter

Reply via email to