go***********@gmail.com wrote:

I have a statement as follows,

a = b++;

why b=b+1 after a=b. I check the C language precedence (K&R Page 52) ,

++ should has higher precedence than = .

Rick

Let's define a new operator, @. @ has the following semantics. The

expression @x evaluates to the value x+1. The expression x@ evaluates

to the value of x. In neither case does the value of x change.

Now, let's let x = 3. What are the values of x, y and z after the

following assignments?

y = @x ;

z = x@ ;

Obviously, x = 3, y = 4 and z = 3.

The only difference between the @ operator I made up, and the ++

operator is that ++ has a side effect of incrementing the variable to

which it is applied. It still holds that ++x evalutes to the value x+1,

and x++ evalutes to the value of x.

Now, to answer your question, "a=b" doesn't happen anywhere, never, not

at all, not before "b++", and not after "b++". What happens is that,

first, the expression "b++" is evaluated. This expression evaluates to

whatever the value of b is (before incrementing). It makes no

difference that as a side effect b then gets incremented. So then, the

result of of the expression "b++" (which is b's old value) gets assigned

to a.