Reputation: 31
The pointer points to a struct which contains an array. How do I get the memory location of each element of the array in the pointer?
ptr->array[a]
Upvotes: 1
Views: 67
Reputation: 67195
You can use the address-of operator (&) to get the address of a variable. (As in &ptr->array[a]
.)
However, since ptr->array
is already an address, you can also use the syntax ptr->array + a
.
Upvotes: 0
Reputation: 26476
and also ptr->array+a
, becuase of pointer arithmetics. but use @Vaughn Cato way for readability.
Upvotes: 0
Reputation: 64308
Using &ptr->array[a]
will give you a pointer to element a
within ptr->array
.
Upvotes: 2