🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #4208

Re: order of execution with && and ||

#4208
From: Christopher R. Volpe
Date: Tue, 10 Oct 1995 03:22
22 lines
1312 bytes
In article <45bbtn$t8o@goanna.cs.rmit.EDU.AU>, s9511800@yallara.cs.rmit.edu.au (Simon Harris ) writes:
>What is the order of execution (resolution) for statements with && and ||?
>
>E.G. Given the following:
>
>	if (ptr != (char *) 0 && *ptr == 'a')
>
>does this get resolved left to right?

Equality operators have higher precedence than boolean operators.
Boolean operators evaluate their left operand first, and then the right
operand, if necessary to determine the result. (This conditional evaluation of
the right operand is known as short-circuit evaluation.)

You can find this and further details in any book on C, including Kernighan &
Ritchie 2nd edition.

--

Chris Volpe				Phone: (518) 387-7766 (Dial Comm 8*833
GE Corporate R&D			Fax:   (518) 387-6560
PO Box 8, Schenectady, NY 12301		Email: volpecr@crd.ge.com
Technical Details
Message-ID: <45cot5$57@rdsunx.crd.ge.com>
Path: arc1-ca.pugleaf.net!bart.crd.ge.com!volpe
References: <45bbtn$t8o@goanna.cs.rmit.EDU.AU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!bart.crd.ge.com!volpe
From: volpe@bart.crd.ge.com (Christopher R. Volpe)
Newsgroups: comp.std.c
Subject: Re: order of execution with && and ||
Date: 10 Oct 1995 03:22:13 GMT
Organization: GE Corporate Research & Development
Sender: volpe@bart (Christopher R. Volpe)
Distribution: world
Message-ID: <45cot5$57@rdsunx.crd.ge.com>
References: <45bbtn$t8o@goanna.cs.rmit.EDU.AU>
Reply-To: volpe@ausable.crd.ge.com
NNTP-Posting-Host: bart.crd.ge.com