Article View: comp.std.c
Article #4211Re: order of execution with && and ||
From: Ralf Schneeweiss
Date: Tue, 10 Oct 1995 13:04
Date: Tue, 10 Oct 1995 13:04
38 lines
1097 bytes
1097 bytes
Simon Harris (s9511800@yallara.cs.rmit.edu.au) wrote:
: 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?
From left to right. In some cases the right condition will not be tested.
Try this:
#include <stdio.h>
int a( void )
{
printf("a\n");
return 0;
}
int b( void )
{
printf("b\n");
return 1;
}
main()
{
if( a() && b() ) /* in this case b() is not executed */
{
}
if( a() || b() )
{
}
}
Ralf <ralf.schneeweiss@student.uni-tuebingen.de>
Technical Details
Message-ID:
<45dr1r$jn3@newsserv.zdv.uni-tuebingen.de>Path:
arc1-ca.pugleaf.net!newsserv.zdv.uni-tuebingen.de!hp24!zxmkn10References:
<45bbtn$t8o@goanna.cs.rmit.EDU.AU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newsserv.zdv.uni-tuebingen.de!hp24!zxmkn10 From: zxmkn10@hp24.zdv.uni-tuebingen.de (Ralf Schneeweiss) Newsgroups: comp.std.c Subject: Re: order of execution with && and || Date: 10 Oct 1995 13:04:59 GMT Organization: InterNetNews at ZDV Uni-Tuebingen Message-ID: <45dr1r$jn3@newsserv.zdv.uni-tuebingen.de> References: <45bbtn$t8o@goanna.cs.rmit.EDU.AU> NNTP-Posting-Host: hp24.zdv.uni-tuebingen.de X-Newsreader: TIN [version 1.2 PL2]