Frames Catherine White
Frames Catherine White

Reputation: 28232

arrays / pointers (C)

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

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

Upvotes: 3

Views: 286

Answers (4)

James Black
James Black

Reputation: 41848

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.

Upvotes: 2

BobbyShaftoe
BobbyShaftoe

Reputation: 28499

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]

Upvotes: 9

Buggieboy
Buggieboy

Reputation: 4696

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

Upvotes: 0

Terry Shi
Terry Shi

Reputation: 1028

The simple answer is: Yes.

Upvotes: 0

Related Questions