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 6955885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:47:45+00:00 2026-05-27T14:47:45+00:00

I am a little confused about how the C# compiler handles pre- and post

  • 0

I am a little confused about how the C# compiler handles pre- and post increments and decrements.

When I code the following:

int x = 4;
x = x++ + ++x;

x will have the value 10 afterwards. I think this is because the pre-increment sets x to 5, which makes it 5+5 which evaluates to 10. Then the post-increment will update x to 6, but this value will not be used because then 10 will be assigned to x.

But when I code:

int x = 4;
x = x-- - --x;

then x will be 2 afterwards. Can anyone explain why this is the case?

  • 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-05-27T14:47:46+00:00Added an answer on May 27, 2026 at 2:47 pm

    x-- will be 4, but will be 3 at the moment of --x, so it will end being 2, then you’ll have

    x = 4 - 2
    

    btw, your first case will be x = 4 + 6

    Here is a small example that will print out the values for each part, maybe this way you’ll understand it better:

    static void Main(string[] args)
    {
        int x = 4;
        Console.WriteLine("x++: {0}", x++); //after this statement x = 5
        Console.WriteLine("++x: {0}", ++x); 
    
        int y = 4;
        Console.WriteLine("y--: {0}", y--); //after this statement y = 3
        Console.WriteLine("--y: {0}", --y);
    
        Console.ReadKey();
    }
    

    this prints out

    x++: 4
    ++x: 6
    y--: 4
    --y: 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a little confused about how C++ handles includes. I have something like: typedef
I am a little confused about Accept-Encoding . I have Web Service which would
I'm a little confused about how EGit workes. I have an existing git repository
I am a little confused about overloading rules, let's say there are following literal
Am a little confused about the javascript object,say I have the DOM below <div
I am a little confused about when do I have to serialize objects using
I'm a little confused about the Grails HQL documentation. Say I have a domain
I am little confused about setting events in .NET. I have methods that is
I'm a little confused about the python in operator for sets. If I have
I'm a little confused about how the standard library will behave now that Python

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.