Zachary Griggs wrote:So, in "a = ++n", the ++n operator means the ++ takes place first. In other words, it's essentially doing the following: "n++; a = n"
In "b = n++", the ++ happens last. So you can think of it as: "b = n; n++"
Campbell Ritchie wrote: Here the whole expression j++ has the old value of j and the incremented value is hidden until the next time you use j.
Zachary Griggs wrote:So, in "a = ++n", the ++n operator means the ++ takes place first. In other words, it's essentially doing the following: "n++; a = n"
In "b = n++", the ++ happens last. So you can think of it as: "b = n; n++"
I think that is an accurate way to describe x++, yes.Cosmid Constantine wrote:. . . . if post increment has a higher precedence than pre increment, why does it take effect later than pre. . . . n++ has higher precedence . . . but . . . it hides its calculated value. . . .
Cosmid Constantine wrote:Hi,
Sample program:
n = 0;
a = ++n;
b = n++;
If the postincrement or postdecrement operator has higher precedence than the preincrement or predecrement operator, then why b didn't get a value of 2? I mean, it would make more logical sense if a = 0 and b = 2 with the precedence of the two.
I guess my question is, if n++ has higher precedence, why didn't it apply the ++ effect sooner than the ++ on the ++n? Is this just a special case in Java?
Thanks
1 + 1 = 10 is always one of the plausible truths for me.
Afraid that is incorrect. The increment to n occurs first. But the value of n++ is not incremented, i.e. n++ has the old value of n.Mark Ii wrote:. . . postfix increment operator is used. b is assigned the current value of n first which is 1 then n is incremented. . . .
Campbell Ritchie wrote:
Afraid that is incorrect. The increment to n occurs first. But the value of n++ is not incremented, i.e. n++ has the old value of n.Mark Ii wrote:. . . postfix increment operator is used. b is assigned the current value of n first which is 1 then n is incremented. . . .
1 + 1 = 10 is always one of the plausible truths for me.
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
Thread Boost feature
https://coderanch.com/t/674455/ThreadBoostfeature
