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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:00:16+00:00 2026-05-14T03:00:16+00:00

In an if statement with multiple conditionals, is the second conditional executed if the

  • 0

In an if statement with multiple conditionals, is the second conditional executed if the outcome of the first is clear?

example:

if(i>0 && array[i]==0){
}

If I swap the conditionals a segfault may occur for negative values of i, but this way no segfault occurs. Can I be sure that this always works or do have have to use nested if statements?

  • 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-14T03:00:16+00:00Added an answer on May 14, 2026 at 3:00 am

    This type of evaluation is called short-circuiting.
    Once the result is 100% clear, it does not continue evaluating.

    This is actually a common programming technique.
    For example, in C++ you will often see something like:

    if (pX!=null && pX->predicate()) { bla bla bla }
    

    If you changed the order of the conditions, you could be invoking a method on a null pointer and crashing. A similar example in C would use the field of a struct when you have a pointer to that struct.

    You could do something similar with or:

    if(px==null || pX->isEmpty()} { bla bla bla }
    

    This is also one of the reasons that it is generally a good idea to avoid side effects in an if condition.

    For example suppose you have:

    if(x==4 && (++y>7) && z==9)
    

    If x is 4, then y will be incremented regardless of the value of z or y, but if x is not 4, it will not be incremented at all.

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

Sidebar

Related Questions

I'm trying a simple multiple conditional statement which should work fine with PHP but
Is there a way to have a statement across multiple lines without the underscore
I need write an update statement that used multiple tables to determine which rows
I know you can combine multiple table-selects using a Join statement but is there
I know that I can insert multiple rows using a single statement, if I
I want to do a conditional statement in my prototype such as: if (${EXECUTABLE_NAME}
Is it ok to use conditional operators like a statement like so? (x ==
Following linq statement generates multiple trips to the database, is there a way to
I am using multiple joins in a statement and Have tried to make linq-to-SQl
PHP has a language construct list() which provides multiple variables assignment in one statement.

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.