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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:05:42+00:00 2026-06-13T18:05:42+00:00

could someone explain why this code output is not equals not equals 2 in

  • 0

could someone explain why this code output is

not equals
not equals 2

in the first if statement it seems that a = 0 b/c is a postfix increment; therefore a will not increase untile next line; however, the two a’s are not equal why? and in the second if when I run the debugger the value of a is 2, but the test is false, why?

public static void main (String[] args)
   {
       int a = 0;
       if (a++ == a++) {
           System.out.println("equals");
       } else {
           System.out.println("not equals");
       }

       if (++a == 2) {
           System.out.println("equals 2");
       } else {
           System.out.println("not equals 2");
       }

   } 
  • 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-13T18:05:43+00:00Added an answer on June 13, 2026 at 6:05 pm

    a++(post increment) would increment a first and then assign it to the variable. in your first case

    (a++==a++) in the first post increment a value would be incremented by 1 first but not assigned yet, but when it reaches the second a++, now the a value is assigned and you are incrementing it again.

    for example

    if say a=0;
    
    (a++==a++) would be (0==1)
    

    so now the a value would be 2 after evaluating the if.

    for your second case

    (++a==2) here a would be incremented to 3 , (3==2) which is false thus the else if executed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could someone explain me why this code is not working : ... foreach (VisualChunk
Could someone explain to me what this portion of code means? repeat scroll 0
Could someone explain this (strange) behavior? Why is the length in the first example
Please could someone explain to me why this regex does not match anything, when
Could someone help me explain this? I have two snippets of code, one works
Could someone help explain this code to me? .text:00401270 ; int __cdecl main(int argc,const
Can someone explain why the output of this code is true true , instead
I don't understand what this code is doing at all, could someone please explain
Could someone explain what this code does size = *(int *)data; // size of
Could someone please explain why this is happening; this following is the code I’ve

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.