Using the transitivity of addition (meaning that A+B == B+A) we can
get some pretty ugly, but valid, syntax when indexing into arrays:
So arr[N] == *(arr + N) then we apply the transitivity rule on the
left hand giving *(N + arr) and then go back to the array-form gives
N[arr].
So given array arr then 2[arr] will give the third element in arr. And
then we replace the N with a variable and we get something like this:
int main()
{
int arr[3] = {1, 2, 3};
for (int i = 0; i < 3; ++i)
std::cout << i[arr];
return 0;
}
[/quote]
原文:
http://groups.google.com/group/comp.lang.c++/browse_thread/thread/599be6c63ddaba57?hl=en
联系客服