Re: C
Re: C
- Subject: Re: C
- From: Clark Cox <email@hidden>
- Date: Sat, 30 Aug 2003 19:03:28 -0400
On Friday, August 29, 2003, at 15:47, David Thorp wrote:
I can't actually find this in any of my documentation to confirm for
certain, but I do believe that the && has either the same or higher
precedence than !=. Please somebody else correct me if I'm wrong
here.
You're wrong :)
Therefore you need to put parentheses in the conditions for your while
statement:
11: while ((index < 31) && (temp[index-1] != 555));
to ensure that the != and the < are evaluated before the &&.
I never bother to remember precedence rules. I just make sure I put
parentheses in anyway (like the above for example) to ensure the right
result, regardless of precedence.
That's very bad advice. It's best to actually know what's going on,
than to use parentheses "just in case". There are so many references
from which you can get this information (a google search for "C
operator precedence" turned up 218,000 results); not knowing it is
inexcusable. It would be as if, in a middle school algebra class, a
student said "I don't need to know that multiplication has a higher
precedence that addition, I'll just put parentheses in anyway".
Basically, they break down like so:
1) () [] -> .
2) ! ~ ++ -- -(negation) * (pointer dereference) &(address of) sizeof
3) * / %
4) + -
5) << >>
6) < <= > >=
7) == !=
8) &
9) ^
10) |
11) &&
12) ||
13) ?:
14) = += -= (and other assignments)
15) ,
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
- Follow-Ups:
- Re: C
- From: David Thorp <email@hidden>
- Re: C
- From: cricket <email@hidden>
References: | |
| >Re: C (From: David Thorp <email@hidden>) |