tags:

views:

177

answers:

4

in C is: *(array) equivalent to array[0]?

Therefore is *(array+2) equivalent to array[2]?

A: 

The simple answer is: Yes.

CyberSnoopy
A: 

Yes and yes. (Padding to required 15 character length.)

Buggieboy
+8  A: 

Yes, for instance:

given:

int a[10];

Then

*(a + 2)

is equivalent to

a[2]

and just for good measure.

a[2]

is equivalent to

2[a]
BobbyShaftoe
OK, you lost me. How can 2[a] = a[2]?
James Black
Yup storage address 2 plus addres of "a" is the same as address of "a" plus 2!
James Anderson
Addition is commutative.
drhirsch
@[James Black]: http://c-faq.com/aryptr/joke.html
Sinan Ünür
Nice point on `2[a]`. +1
Tim
I had a boss that called that "arraying through and index"... :)
dicroce
+1  A: 

You may want to look at this, for more help: http://www.ibiblio.org/pub/languages/fortran/append-c.html

4) Taking a subscript with value i is equivalent to the operation: "pointer-add i and then type-dereference the sum", i.e.

      xxx[i] = *(xxx # i)

As others mentioned, the answer is yes, but you may want to get a better understanding.

James Black