Thread: Pointers

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    26

    Pointers

    If I let p be a pointer attached to the first element of an integer array. Could someone explain the difference between the C operators (*p)++ and *(p++)?

    cheers

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,345
    What is the difference between *p and p++?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    104
    I'm assuming your question is a doubt concerning the other thread you posted.

    Basically, when doing:
    Code:
    int *p = arr;
    The pointer 'p' is pointing to the array's first element's address. When doing:
    Code:
    (*p)++
    You are not referring to the pointer's address, rather to its value, which is insignificant to us at this point. Because, you are dereferencing the pointer. The other way (*(p++)), you are actually referencing the array's address and summing one to it, which would lead the array to return the next element in the array.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    (*p)++

    Add one to the value at p.

    *(p++)

    Give the value at p, then add one unit to the address of p, a unit being the size of the datatype.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM