Article View: comp.std.c
Article #4227Re: order of execution with && and ||
From: Jonas J. Schlein
Date: Sun, 15 Oct 1995 02:40
Date: Sun, 15 Oct 1995 02:40
17 lines
1063 bytes
1063 bytes
|> 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? If by left to right you mean, "Will (ptr != (char *) 0) be executed before (*ptr == 'a')?" then the answer is yes. Actually in your case all 3 operators, i.e. !=, &&, and ==, are left to right associativity so you're perfectly safe. And the second part is guaranteed not to execute at all if the first fails due to short circuit evaluation. -- "If it wasn't for C, we would be using BASI, PASAL, and OBOL." Jonas J. Schlein (schlein@gl.umbc.edu)
Technical Details
Message-ID:
<45psab$fnf@umbc9.umbc.edu>Path:
arc1-ca.pugleaf.net!news.umbc.edu!not-for-mailReferences:
<45bbtn$t8o@goanna.cs.rmit.EDU.AU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.umbc.edu!not-for-mail From: schlein@umbc.edu (Jonas J. Schlein) Newsgroups: comp.std.c Subject: Re: order of execution with && and || Date: 14 Oct 1995 22:40:11 -0400 Organization: University of Maryland Baltimore County Message-ID: <45psab$fnf@umbc9.umbc.edu> References: <45bbtn$t8o@goanna.cs.rmit.EDU.AU> NNTP-Posting-Host: f-umbc9.umbc.edu NNTP-Posting-User: schlein