&& operator question 
Author Message
 && operator question

if(expression1 && expression2)
     some statement;

My question is, if expression1 is false will expression2 get evaluated at
all?

____________________________________________________________________________
 ___  ___                                                                   |
|   \/   | Matt Johnson                    | "Government is not the solution|

.--.__|  | http://www.*-*-*.com/ ~gs01maj    | is the problem."               |
|________|                                 |                  Ronald Reagan |
____________________________________________________________________________|



Mon, 03 Aug 1998 03:00:00 GMT  
 && operator question

: if(expression1 && expression2)
:      some statement;

: My question is, if expression1 is false will expression2 get evaluated at
: all?

An ANSI conforming compiler will not evaluate expression2 when expression1
is false.  Similarly, for
      expr1 || expr2

when expr1 is true, expr2 will not be evaluated.

Alan Duchan, Canisius College, Buffalo, NY



Mon, 03 Aug 1998 03:00:00 GMT  
 && operator question

Quote:
>if(expression1 && expression2)
>     some statement;

>My question is, if expression1 is false will expression2 get evaluated at
>all?

No.

This is pretty straightforward, and I would think that the answer can
be found in any decent book on ANSI C. Also look in the comp.lang.c FAQ
and look at questions 3.4 and 3.5 and their answers.

                                                                Z

--
-------------------------------------------------------------------------
| Syed Zaeem Hosain          P. O. Box 610097            (408) 441-7021 |

-------------------------------------------------------------------------



Mon, 03 Aug 1998 03:00:00 GMT  
 && operator question

Quote:


>  > if(expression1 && expression2)
>  >      some statement;
>  > My question is, if expression1 is false will expression2 get evaluated at
>  > all?
> No.   Why do you ask that question here?

If not here, where? This is the C forum. Matthew; if you want control to
fall through if either expression is true why don't you just write
if(exp1 || exp2)
   stamt;
?


Mon, 03 Aug 1998 03:00:00 GMT  
 && operator question

Quote:

> An ANSI conforming compiler will not evaluate expression2 when expression1
> is false.  Similarly, for
>       expr1 || expr2

> when expr1 is true, expr2 will not be evaluated.

Whoops. I guess my solution isn't the way to write the
evaluation (unless you want that effect.) What would be
the effect of writing it:

((exp1) || (exp2)) stamt;?



Mon, 03 Aug 1998 03:00:00 GMT  
 && operator question

 >if(expression1 && expression2)
 >     some statement;
 >My question is, if expression1 is false will expression2 get evaluated at
 >all?

No, it won't.

                                                                robert



Mon, 03 Aug 1998 03:00:00 GMT  
 && operator question
 >

 >

 > >  > if(expression1 && expression2)
 > >  >      some statement;
 > >  > My question is, if expression1 is false will expression2 get evaluated at
 > >  > all?

 > > No.   Why do you ask that question here?

 > Why wouldn't he ask it here? It is a C question...

I am trying to understand why someone would go to the trouble (and have the
patience) to ask such a trivial question that could easily be answered by
consultation to any C language textbook.    

I have a slightly hidden agenda as well by posting this reply in the newsgroup
....that is the general education of the infrequent readers of this group....
that such simple questions should first be resolved privately.     Or at least,
disquise the question in sheep's clothing....for example:

   Why is C designed to require short circuit evaluation with respect to
   some operators (for instance &&) ?    

   Isn't C somewhat unique in mandating short circuit evaluation for the
   logical AND (&&) operator?  BASIC and fortran don't do this.

   Why did the designers of C mandate the short circuit evaluation of the
   && operator?

That way, you'll be quickly informed if your assumption is incorrect
(you get to ask the question) and be much less likely to get "educated"
about the nettiquete issues.   You also just might learn some background
about the C language, as well as the operational realities.   But better
by far to just read a book (you'll get the answer instantly).



Mon, 03 Aug 1998 03:00:00 GMT  
 && operator question

Quote:


>>  > if(expression1 && expression2)
>>  >      some statement;

>>  > My question is, if expression1 is false will expression2 get evaluated at
>>  > all?

>> No.   Why do you ask that question here?

>Why wouldn't he ask it here? It is a C question...

Not all C questions should be asked here.  Some of them are answered by
C books, others by the FAQ of this newsgroup.

Dan
--
Dan Pop
CERN, CN Division

Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland



Tue, 04 Aug 1998 03:00:00 GMT  
 && operator question

Quote:



>>  > if(expression1 && expression2)
>>  >      some statement;

>>  > My question is, if expression1 is false will expression2 get evaluated at
>>  > all?

>> No.   Why do you ask that question here?

>Why wouldn't he ask it here? It is a C question...

Yes, but about as elementary as it can get. Almost any book on C will
discuss it - even the FAQ has a sort of reference in it and it did not
take me much time to find it either. People should make the effort to
read books on C, and the comp.lang.c FAQ, before posting here.

                                                                Z

--
-------------------------------------------------------------------------
| Syed Zaeem Hosain          P. O. Box 610097            (408) 441-7021 |

-------------------------------------------------------------------------



Wed, 05 Aug 1998 03:00:00 GMT  
 && operator question

Quote:




>  > >  > if(expression1 && expression2)
>  > >  >      some statement;
>  > >  > My question is, if expression1 is false will expression2 get evaluated at
>  > >  > all?

>  > > No.   Why do you ask that question here?

>  > Why wouldn't he ask it here? It is a C question...

> I am trying to understand why someone would go to the trouble (and have the
> patience) to ask such a trivial question that could easily be answered by
> consultation to any C language textbook.

> I have a slightly hidden agenda as well by posting this reply in the newsgroup
> ....that is the general education of the infrequent readers of this group....
> that such simple questions should first be resolved privately.     Or at least,
> disquise the question in sheep's clothing....for example:

>    Why is C designed to require short circuit evaluation with respect to
>    some operators (for instance &&) ?

>    Isn't C somewhat unique in mandating short circuit evaluation for the
>    logical AND (&&) operator?  BASIC and FORTRAN don't do this.

>    Why did the designers of C mandate the short circuit evaluation of the
>    && operator?

> That way, you'll be quickly informed if your assumption is incorrect
> (you get to ask the question) and be much less likely to get "educated"
> about the nettiquete issues.   You also just might learn some background
> about the C language, as well as the operational realities.   But better
> by far to just read a book (you'll get the answer instantly).

    While I agree a look in any C text should've cleared this up. I DO
  NOT agree that simply stating the question in an overly verbose and
  pretentious manner makes it somehow OK.  That's akin to the old
  verbage that BS that has passed thru a computer has somehow become
  enobled. Poppy{*filter*}! It's still BS.
    In any event as long as the poster has made some attempt to resolve
  his/her own question thru traditional means, vice knee jerk reaction
  to post, the question is legitimate.

regards,
H.Cross



Thu, 06 Aug 1998 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. C Question - pointer & address-operator

2. Bitwise & operator question

3. Bitwise & operator tricky question

4. ***&&&>>> HELP --- CXL --- HELP <<<&&&****

5. Preprocessor Question: #if A && B

6. Question on && ==

7. Preprocessor Question: #if A && B

8. Question about &&.

9. Odd trivia question involving && and ,

10. A question about '&&'

11. Preprocessor Question: #if A && B

12. Preprocessor Question: #if A && B

 

 
Powered by phpBB® Forum Software