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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:40:54+00:00 2026-06-18T07:40:54+00:00

I set a similar question a few weeks ago but I cannot still dissolve

  • 0

I set a similar question a few weeks ago but I cannot still dissolve the ambiguity and the confusion on java operators precedence. This time I have this fragment of code:

int mask = 0;
int count = 0;
if( ((5<7) || (++count < 10)) | mask++ < 10 )   
    mask = mask + 1;
System.out.println(mask + " " + count);

The result is (unexpectedly to me): 2 0.

Moreover, the compiler provides a warning underlining only the expression (++count<10): dead code.

I reckon however the execution of the code though as either one of the following ways:

1) | has a higher precedence than ||, hence it is considered as there were parenthesis around the expression ( (++count<10) | mask++ <10). This way the compiler should have executed the both parts and count should have been set to 1 (++count<10).

2) If the compiler looks first the (5<7) and after evaluating it to false skips the entire second expression, then mask should not have been increased and we would wait the value 1 in the output.

What have I misunderstood and cannot explain the behavior of the compiler, as well as the output?

  • 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-18T07:40:55+00:00Added an answer on June 18, 2026 at 7:40 am

    || is an OR operator that only evaluates its right hand side expression if the left hand side expression is false. In your case, 5 < 7 is true and ++count < 10 is not evaluated.

    On the other hand, | always evaluates both expressions: even if ((5<7) || (++count < 10)) is true, mask++ < 10 will be evaluated.

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

Sidebar

Related Questions

I asked a pretty similar question a few days ago, but this one is
I asked a similar question a few days ago, but there's no harm in
I've read a few other questions that seem similar but I'm still very confused,
Hello I posted a few days ago a similar question and I was told
Ok so I looked at quite a few similar questions, but I'm still a
my issue lokks similar to this one: (link) but i have one-to-many association: <set
I started working with C# a few weeks ago and I'm now in a
Similar to this Java question . I would like to specify that a variable
My question in similar to git remove commit from a merge but I can't
I realise this question is similar to this one but I think mine is

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.