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

In Java, what would the best way be to have a constantly listening port
I've been seeing so much recently about functional programming and Clojure looks particularly interesting.
Quite often, in programming we get situations where null checks show up in particularly
This is not yet particularly programing related but, I am very interested in how
This question is about programming small microcontrollers without an OS. In particular, I'm interested
I have some questions about multi-threaded programming and multi-core usage. In particular I'm wondering
I understand the basics of dataflow programming and have encountered it a bit in
After reading this very informative (albeit somewhat argumentative) question I would like to know
This has to be a common question that all programmers have from time to
I've been doing object-oriented programming for most of the past 7 years, using Java

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.