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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:04:04+00:00 2026-05-23T23:04:04+00:00

I recently came across something that I thought I understood right off the bat,

  • 0

I recently came across something that I thought I understood right off the bat, but thinking more on it I would like understanding on why it works the way it does.

Consider the code below. The (x-- == 9) is clearly getting evaluated, while the (y++ == 11) is not. My first thought was that logical && kicks in, sees that the expression has already become false, and kicks out before evaluating the second part of the expression.

The more I think about it, the more I don’t understand why this behaves as it does. As I understand it, logical operators fall below increment operations in the order of precedence. Shouldn’t (y++ == 11) be evaluated, even though the overall expression has already become false?

In other words, shouldn’t the order of operations dictate that (y++ == 11) be evaluated before the if statement realizes the expression as a whole will be false?

#include <iostream>
using namespace std;

int main( int argc, char** argv )
{
    int x = 10;
    int y = 10;

    if( (x-- == 9) && (y++ == 11) )
    {
        cout << "I better not get here!" << endl;
    }

    cout << "Final X: " << x << endl;
    cout << "Final Y: " << y << endl;
    return 0;
}

Output:

Final X: 9
Final Y: 10
  • 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-23T23:04:06+00:00Added an answer on May 23, 2026 at 11:04 pm

    logical operators fall below increment operations in the order of
    precedence.

    Order of precedence is not order of execution. They’re completely different concepts. Order of precedence only affects order of execution to the extent that operands are evaluated before their operator, and order of precedence helps tell you what the operands are of each operator.

    Short-circuiting operators are a partial exception even to the rule that operands are evaluated before the operator, since they evaluate the LHS, then the operator has its say whether or not to evaluate the RHS, maybe the RHS is evaluated, then the result of the operator is computed.

    Do not think of higher-precedence operations “executing first”. Think of them “binding tighter”. ++ has higher precedence than &&, and in the expression x ++ && y ++, operator precedence means that the ++ “binds more tightly” to y than && does, and so the expression overall is equivalent to (x++) && (y++), not (x++ && y) ++.

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

Sidebar

Related Questions

I recently came across some code that looks something like this: <head> <?php /*
I recently came across an IE7 only bug that I thought I'd share so
I generally prefer constness, but recently came across a conundrum with const iterators that
I work w/ Rhino Mocks 3.5 a lot but recently came across something I
I did quite a reading about Android recently and I came across something that
I came across the following code recently and would like to optimize it: Public
I was reading some Java recently and came across something (an idiom?) new to
I recently came across a ASP 1.1 web application that put a whole heap
I recently came across a Windows library called AHK that gives me great control
I recently came across a html email that contained _label attributes on 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.