SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rank these operators in order they will be evaluated and explain why

    I saw this on an exam a while back but never understood.
    Please explain this one to me

    AND
    &&
    OR
    ||

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)

  3. #3
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your response guido.
    Could you please help me understand why?

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,044
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)
    Short answer - because that's the way it is.

    OK, seriously, I guess the precedence could have been decided arbitrarily. But I like to think that some thought was put into it, or at least copied from that found in other languages.

    TBH I've never worried about it much, I prefer to force the issue by using parentheses. I find it a lot easier to read without needing to remember, and IMHO a few extra characters here and there won't make a significant gain in performance to make it worth the hassle.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •