Thread: Dereferencing

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    32

    Dereferencing

    Hi,

    if I get it right, ap in the following example is a pointer to an array of 10 ints. See the code example for my question.

    Code:
    void somefunc(int (*ap)[10])
    {
      int i = 5, j = 6; 
      printf("%i", (*(ap + i))[j]); // the same as ap[i][j]
      // What would *(ap + i)[j] without the extra brackets refer to?
    }

  2. #2
    Registered User Inanna's Avatar
    Join Date
    May 2011
    Posts
    69
    If you look at this page, [] has higher precedence than *. Without parentheses to swap the order of those two, the *(ap + i)[j] has the effect of *ap[i+j], or ap[i+j][0].

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about -> dereferencing
    By newlearner in forum C Programming
    Replies: 10
    Last Post: 06-22-2009, 12:39 AM
  2. Dereferencing
    By Air in forum C Programming
    Replies: 7
    Last Post: 05-13-2009, 08:53 AM
  3. Dereferencing and Equality?
    By dnguyen1022 in forum C++ Programming
    Replies: 17
    Last Post: 03-06-2009, 01:54 AM
  4. dereferencing a void *
    By pointing in forum C++ Programming
    Replies: 9
    Last Post: 12-06-2002, 02:38 PM
  5. Dereferencing Pointer
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 02-01-2002, 07:52 AM