why my code error from test=++exf++;


1
2
3
4
5
6
7
  main()
{
int exf=25;
int test;
test=++exf++;
printf("exf=%d test=%d",exf,test);
}
Because it's a bad line of code.

When the compiler parses that command, it's like to parse ++exf and recognise a pre-increment operation on exf.

That leaves a ++ remaining. The compiler will see that it has no left hand value and spit out that you're trying to use the post-increment operator on nothing.

What exactly were you trying to achieve?
When the compiler parses that command, it's like to parse ++exf and recognise a pre-increment operation on exf.
It is backward. Post-increment have higher precedence, but returns r-value, so preincrement will not work, because it requires l-value.
If you do test = (++exf)++;, it should work, and test should be equal to ext − 1.

BTW: (++x)-- — twitch operation :)
Last edited on
Yep, I do believe you're right.

Cheers, MiiNiPaa.
If you do test = (++exf)++;, it should work, and test should be equal to ext − 1.

Not really, what you'd have is undefined behavior. You may want to study up a little on sequence points.

what you'd have is undefined behavior
Nope, in this case order of operation changing exf and their result is defined.
You may want to study up a little on sequence points.
There is no sequence points in C++11 standard.
Last edited on
While it's not something you would hope to see anywhere, this is not undefined behavior.
Topic archived. No new replies allowed.