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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:18:44+00:00 2026-05-11T13:18:44+00:00

Does the ANSI standard mandate the logical operators to be short-circuited, in either C

  • 0

Does the ANSI standard mandate the logical operators to be short-circuited, in either C or C++?

I’m confused for I recall the K&R book saying your code shouldn’t depend on these operations being short circuited, for they may not. Could someone please point out where in the standard it’s said logic ops are always short-circuited? I’m mostly interested on C++, an answer also for C would be great.

I also remember reading (can’t remember where) that evaluation order isn’t strictly defined, so your code shouldn’t depend or assume functions within an expression would be executed in a specific order: by the end of a statement all referenced functions will have been called, but the compiler has freedom in selecting the most efficient order.

Does the standard indicate the evaluation order of this expression?

if( functionA() && functionB() && functionC() ) {     cout << "Hello world"; } 
  • 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. 2026-05-11T13:18:45+00:00Added an answer on May 11, 2026 at 1:18 pm

    Yes, short-circuiting and evaluation order are required for operators || and && in both C and C++ standards.

    C++ standard says (there should be an equivalent clause in the C standard):

    1.9.18

    In the evaluation of the following expressions

    a && b a || b a ? b : c a , b 

    using the built-in meaning of the operators in these expressions, there is a sequence point after the evaluation of the first expression (12).

    In C++ there is an extra trap: short-circuiting does NOT apply to types that overload operators || and &&.

    Footnote 12: The operators indicated in this paragraph are the built-in operators, as described in clause 5. When one of these operators is overloaded (clause 13) in a valid context, thus designating a user-defined operator function, the expression designates a function invocation, and the operands form an argument list, without an implied sequence point between them.

    It is usually not recommended to overload these operators in C++ unless you have a very specific requirement. You can do it, but it may break expected behaviour in other people’s code, especially if these operators are used indirectly via instantiating templates with the type overloading these operators.

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

Sidebar

Related Questions

Which version of ANSI C standard does Turbo C 3.0 follow wholly or partly?
I have read in the K&R II C Programming ANSI C book that the
does ansi c allows serial communication on rs232 null modem? if yes then any
Does anyone have a snippit of code to parse apache2 logs with ANSI C?
I have written code in native ANSI C++ that does some complicated numerical analysis.
Does PHP have any standard function(s) to convert Unicode strings to plain, good old-fashioned
Does the ANSI C specification call for size of int to be equal to
Does the Windows console supporsts ANSI control characters?
Why does EndUpdateResource have both Unicode and ANSI versions?
Does anyone know if there is a way to generate different code in 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.