Thomas Sundberg

August 5, 2011

What is the difference between i++ and ++i?

Filed under: Clean Code, Java, Programming, Teaching — Tags: , , , — Thomas Sundberg @ 18:27

This post is available at http://www.thinkcode.se/blog/2011/08/05/what-is-the-difference-between-i++-and-++i

7 Comments »

  1. […] 1. stackoverflow: What is the difference between ++i and i++ 2. Thomas Sundberg: What is the difference between i++ and ++i? LD_AddCustomAttr("AdOpt", "1"); LD_AddCustomAttr("Origin", "other"); […]

    Pingback by Increment operator: difference between ++i and i++ « Learntofish's Blog — November 22, 2011 @ 20:39

  2. Fine

    Comment by Birendra — January 18, 2012 @ 05:06

  3. […] Question: Any difference between i++ and ++i?  Answer: When they are used in the loops, they are the same. But when used outside the loops, they behave differently: “i++ return the original value of i and then increase it by 1; ++i increases i by 1 and then returns the new value.” (Source: youtube video: https://www.youtube.com/watch?v=vyQthubfAoI) Another explanation in text: https://thomassundberg.wordpress.com/2011/08/05/what-is-the-difference-between-i-and-i/ […]

    Pingback by Java Tips for Beginners (3): i++,print, loop, format,convert – Data & Web — June 14, 2016 @ 05:27

  4. #include

    int main()
    {
    int I=6;
    printf(“%d %d %d”,++I,++I,++I);
    return 0;
    }
    What is output and explain it clearly

    Comment by Sampath Kumar — August 21, 2016 @ 09:03

    • What happened when you executed it?

      This looks like an assignment for a course or test. You will have to work on it yourself.

      Production code that looks like that is just stupid and if it exists, refactor it.

      /Thomas

      Comment by Thomas Sundberg — August 21, 2016 @ 09:08

  5. thank you very much , i have gotten thr answer to my question

    Comment by Brains — October 26, 2016 @ 12:59


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: