views:

211

answers:

5

To the first O of the array?

+13  A: 

Yes.

KennyTM
+7  A: 

Correct - *p is equivalent to p[0].

Mark Ransom
+7  A: 

p contains the address of the first O of the array.

Indexing happens like so:

p[i] = *(p+i); //note the pointer arithmetic
Paul Nathan
+10  A: 

Exactly. *p and p[0] are the same. Here are some neat features you want to know:

  • "Pointer notation" generally refers to using the 'dereference' (or 'indirection') operator
  • "Array notation" generally refers to using the brackets and offset value

You can represent an address in memory using either interchangeably:

  • *p is equivalent to p[0]
  • *(p+1) is equivalent to p[1], and more awesomely also equivalent to 1[p]

NOTE:

  • As noted in another response, the general form is that *(p+i) is equivalent to p[i]
  • Also, please don't use i[p]
tjko
I don't think the syntax that allows '1[p]' is awsome. I think the language is confusing enough for beginners that we don't need to point out the dark corners of the language (they will be found as the person gets better).
Martin York
I agree with you about the language being confusing, but the reason I consider this particular point "awesome" is that it implicitly gives us intriguing information about the language's specifications. I think understanding that array notation is simply pointer arithmetic is overlooked. If one knows about pointer arithmetic (commutative property holds) and realizes that the syntax allows for `i[p]`. Then one can gather that these two "notations" are in some ways the same to the compiler -- that's awesome!
tjko
+1 for a more than one sentence answer. -1.9 for mentioning the `1[p]` abomination. net 0 (I rounded up).
caspin
A: 

*p is pointing to first element p[0].

Nikhil K