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

  • Home
  • SEARCH
  • 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 7866211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:19:28+00:00 2026-06-03T00:19:28+00:00

I am confused about the output of this code: int c=3; cout<<(c++)*(c++); I use

  • 0

I am confused about the output of this code:

int c=3;
cout<<(c++)*(c++);

I use gcc and the output is 9, but someone said that it’s undefined behavior, why?

  • 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-03T00:19:29+00:00Added an answer on June 3, 2026 at 12:19 am

    The issue is “Sequence points”:

    http://en.wikipedia.org/wiki/Sequence_point

    A sequence point in imperative programming defines any point in a
    computer program’s execution at which it is guaranteed that all side
    effects of previous evaluations will have been performed, and no side
    effects from subsequent evaluations have yet been performed.

    Sequence points also come into play when the same variable is modified
    more than once within a single expression. An often-cited example is
    the C expression i=i++, which apparently both assigns i its previous
    value and increments i. The final value of i is ambiguous, because,
    depending on the order of expression evaluation, the increment may
    occur before, after, or interleaved with the assignment. The
    definition of a particular language might specify one of the possible
    behaviors or simply say the behavior is undefined. In C and C++,
    evaluating such an expression yields undefined behavior.[1]

    As it happens, I get exactly the same answer – “9” – on both MSVC (Windows) and gcc (Linux). I also get a warning whether I compile with gcc (“C”) or g++ (C++):

    $ g++ -o tmp -Wall -pedantic tmp.cpp
    tmp.cpp: In function "main(int, char**)":
    tmp.cpp:7: warning: operation on "c" may be undefined
    $ ./tmp
    c=9...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to be confused about PHP output buffering. I have code like this:
I am confused about why this code says JPEG files and PNG files are
I am a bit confused about this piece of code. public static void Foo(A
I am very confused about this... Here is an extract from my code.. float
Pretty confused about this because I've verified correct logical output for small enough testcases
I'm a bit confused about the result of this code : #include <stdio.h> #include
I am confused about the XmlReader.Read() output. Hope someone could explain it. It seems
I am a little confused about where to use strong and where to use
From this site: http://www.catalinzima.com/?page_id=14 I've always been confused about how the depth map is
I am kind of confused about how the below code works. In my head

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.