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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:24:59+00:00 2026-06-06T19:24:59+00:00

I have seen this symbol/operator in a block of code: a+=1; But I cannot

  • 0

I have seen this symbol/operator in a block of code:

a+=1;

But I cannot figure out what it does. Can someone help me please?

  • 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-06T19:25:01+00:00Added an answer on June 6, 2026 at 7:25 pm

    From the Java Language Specification:

    A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T) ((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once.

    The last phrase is important if the left-hand side has side effects:

    array[i++] += 1;
    

    This is not equivalent to:

    array[i++] = array[i++] + 1;
    

    The first expression will increment i once. The second will increment i twice and will assign the right-hand value to a different element of array than will the first expression.

    I should note that these kind of side-effect statements are not good programming form, despite the fact that you often find them used.

    The cast is also important because the type of (E1) op (E2) may not be assignment-compatible with E1. For example, if a is of type short, then a++ is not equivalent to a = a + 1. The latter will not compile because the type of a + 1 is int and cannot be assigned to a short variable without a cast. That’s why the spec in this case says that a++ is equivalent to a = (short) ((a) + (1)). The same thing goes if a is of type char or byte.

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

Sidebar

Related Questions

I have seen this code documented in the tk docs, but I can't figure
i have seen this block of code in this Stackoverflow as a answer of
I have seen this talked about but never answered. Maybe it has and I'm
I probably should have, but I've never seen this before. Ran into it when
I have seen the clojure symbol -> used in many places, but I am
I have a code that does something like this: char16_t msg[256]={0}; //... wstring wstr;
I have seen this thread already - How can I unshorten a URL? My
I have seen this question a couple of times here in SO but none
I have seen this code on a website and user who posted this code
I have seen this problem before but I haven't seen an answer to the

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.