Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8499985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:48:57+00:00 2026-06-11T00:48:57+00:00

Possible Duplicate: Unsequenced value computations (a.k.a sequence points) Undefined Behavior and Sequence Points Operator

  • 0

Possible Duplicate:
Unsequenced value computations (a.k.a sequence points)
Undefined Behavior and Sequence Points
Operator Precedence vs Order of Evaluation

I’m still trying to wrap my head around how the following expression results in undefined behavior:

a = a++;

Upon searching SO about this, I found the following question:

Difference between sequence points and operator precedence? 0_o

I read through all the answers but I still am having difficulty with the details. One of the answers describes the behavior of my above code example as ambiguous, in terms of how a is modified. For example, it could come down to either of these:

a=(a+1);a++;
a++;a=a;

What exactly makes a‘s modification ambiguous? Does this have to do with CPU instructions on different platforms, and how the optimizer can take advantage of the undefined behavior? In other words, it seems undefined because of the generated assembler?

I don’t see a reason for the compiler to use a=(a+1);a++;, it just looks quirky and doesn’t make much sense. What would possess the compiler to make it behave this way?

EDIT:

Just to be clear, I do understand what is happening, I just don’t understand how it can be undefined when there are rules on operator precedence (which essentially defines the order of evaluation of the expression). Assignment happens last in this case, so a++ needs to be evaluated first, to determine the value to assign to a. So what I expect is that a is modified first, during the post-fix increment, but then yields a value to assign back to a (second modification). But the rules for operator precedence seem to make the behavior very clear to me, I fail to find where there is any “wiggle-room” for it to have undefined behavior.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:48:59+00:00Added an answer on June 11, 2026 at 12:48 am

    The first answer in the question you linked to explains exactly what’s going on. I’ll try to rephrase it to make it more clear.

    Operator precedence defines the order of the computation of values via expressions. The result of the expression (a++) is well understood.

    However, the modification of the variable a is not part of the expression. Yes, really. This is the part you’re having trouble understanding, but that’s simply how C and C++ define it.

    Expressions result in values, but some expressions can have side effects. The expression a = 1 has a value of 1, but it also has the side effect of setting the variable a to 1. As far as how C and C++ define things, these are two different steps. Similarly, a++ has a value and a side-effect.

    Sequence points define when side effects are visible to expressions that are evaluated after those sequence points. Operator precedence has nothing to do with sequence points. That’s just how C/C++ defines things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How an uninitialised variable gets a garbage value? So when an undefined
Possible Duplicate: Pre & post increment operator behavior in C, C++, Java, & C#
Possible Duplicate: What does Asynchronous means in Ajax? jQuery ajax return value Trying to
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: array_splice() for associative arrays How to add an array value to the
Possible Duplicate: php == vs === operator Reference - What does this symbol mean
Possible Duplicate: What is the fastest XML parser in PHP? I still need to
Possible Duplicate: Simple and clean xml manipulation in PHP I trying to reference specific
Possible Duplicate: Trying to get tables next to each other horizontal I have two
Possible Duplicate: Variable name as a string in Javascript What I'm trying to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.