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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:29:41+00:00 2026-05-22T18:29:41+00:00

In programming, particularly in Java, what is the difference between: int var = 0;

  • 0

In programming, particularly in Java, what is the difference between:

int var = 0;
var++;

and

int var = 0;
++var;

What repercussions would this have on a for loop?

e.g.

for (int i = 0; i < 10; i++) {}

for (int i = 0; i < 10; ++i) {}
  • 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-22T18:29:41+00:00Added an answer on May 22, 2026 at 6:29 pm

    tldr;

    Although both var++ and ++var increment the variable they are applied to, the result returned by var++ is the value of the variable before incrementing, whereas the result returned by ++var is the value of the variable after the increment is applied.

    Further Explanation

    When ++var or var++ form a complete statement (as in your examples) there is no difference between the two. For example the following

    int x = 6;
    ++x;
    assert x == 7;
    

    is identical to

    int x = 6;
    x++;
    assert x == 7;
    

    However, when ++var or var++ are used as part of a larger statement, the two may not be equivalent. For example, the following assertion passes

    int x = 6;
    assert ++x == 7;
    

    whereas this one fails

    int x = 6;
    assert x++ == 7;
    

    Although both var++ and ++var increment the variable they are applied to, the result returned by var++ is the value of the variable before incrementing, whereas the result returned by ++var is the value of the variable after the increment is applied.

    When used in a for loop, there is no difference between the two because the incrementation of the variable does not form part of a larger statement. It may not appear this way, because there is other code on the same line of the source file. But if you look closely, you’ll see there is a ; immediately before the increment and nothing afterwards, so the increment operator does not form part of a larger statement.

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

Sidebar

Related Questions

When I'm programming in Java (or a similar language), I often employ a simple
I am helping a colleague set up some GUI programming tools I have written
This is a Rails 3 application. I have images that can be tied to
I have been programming on iPhone for quite sometime and have had bad experiences
Disclaimer: I apologize if this is too subjective and perhaps it may be better
So I was under the impression that any mistake made in programming could quite
I am a long-term user of Java (but I am a scientist and not
I have just started learning Python & have come across namespaces concept in Python.
I have a question about Apache Commons projects . We know there are many
I am rather new to Android programming in general and am having particular difficulty

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.