Thread: Quick confirmation on operator precedence please

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    27

    Quick confirmation on operator precedence please

    Hi, all. I need someone to confirm that I've got this precedence right below please. Let's say I have a pointer p pointing to some valid stuff somewhere. Then:

    Code:
    if (*p++ == 12)
    is the same as:

    Code:
    p++;
    if (*p == 12)
    Is that correct. Or is it the other way around (i.e. do the comparison first, then increment p to the next address?

    Thank you very much.

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094

  3. #3
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Test it!

    "Sciences are vain and full of errors, which do not spring from experiment, the
    source of all certainty - Leonardo Da Vinci"


    http://www.cppreference.com/operator_precedence.html
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Is that correct.
    I agree with Richie T, it would take <5 mins to answer, yet now 5+ hours have passed.
    And the answer is no.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 10:33 AM
  3. recursive quick sort - stack overflow
    By Micko in forum C Programming
    Replies: 9
    Last Post: 01-01-2005, 05:51 PM
  4. Quick Sort Help
    By NavyBlue in forum C Programming
    Replies: 1
    Last Post: 03-02-2003, 10:34 PM
  5. Replies: 0
    Last Post: 04-30-2002, 07:24 PM