• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C


  • Subject: Re: C
  • From: David Thorp <email@hidden>
  • Date: Sun, 31 Aug 2003 09:30:43 +1000

Thanks to Clark and others who have corrected my error. I probably shouldn't have responded to the original post, since I'm a relative newbie myself, and others gave much clearer (and obviously more correct) responses. I was merely trying to give something back in a roundabout sort of way, but that never works if you don't do it right!

Anyway my apologies for a bad post, and thanks again for the corrections.

David.


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.

References: 
 >Re: C (From: Clark Cox <email@hidden>)

  • Prev by Date: Re: C
  • Next by Date: Re: Enough with the newbie C questions!
  • Previous by thread: Re: C
  • Next by thread: Re: C
  • Index(es):
    • Date
    • Thread