ZE0TRON
ZE0TRON

Reputation: 104

*(x+i) is same as &x[i]?

Question 3 on Career Ride suggests that *(x+i) is the same as &x[i]. Can someone please explain whether this is correct?

Upvotes: 2

Views: 1179

Answers (3)

0___________
0___________

Reputation: 67546

To be more funny none of the answers on that page is correct. Lovely website :)

a. *(x + n) is same as &x[n] WRONG

b. *&x[n] is same as x + n WRONG

c. *(x + n) is same as x[n] +1 WRONG

d. *(x + n) is same as *x[n] WRONG

Upvotes: 3

Carl Norum
Carl Norum

Reputation: 224944

That answer is incorrect. Given a pointer variable x and an integer variable i, *(x + i) is the same as x[i] and x + i is the same as &x[i]. It looks like they took half from each side of that for their answer, but they didn't provide any explanation, so we'll never know.

Upvotes: 9

coder
coder

Reputation: 12972

It not the same:

*(x+i): returns the content of the ith element in x array/pointer

&x[i]: returns the address of the ith element in x array/pointer

Upvotes: 5

Related Questions