Thread: Precedence question

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    65

    Precedence question

    What does *++x mean when x is a pointer to an int?
    Are *(x++) and *(++x) the same?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    *(x++) will increment x (make it point to the next integer in line) after dereferencing, while *(++x) will increment x before.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    65
    So the parentheses don't do anything?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You mean between *(x++) and *x++? Those are the same. The parentheses are redundant in *++x, since there's no way to interpret that other than pre-increment x, then dereference.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    65
    I mean between *(x++) and *(++x).

  6. #6
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,775
    Quote Originally Posted by jw232 View Post
    I mean between *(x++) and *(++x).
    Difference here is not in parentheses. So what is the actual question?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by jw232 View Post
    I mean between *(x++) and *(++x).
    Tabstop answered that in his first post.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM