And now for something completely different. Was: String.join revisited (URGENT for 1.6)
Johannes Stezenbach
yawyi at gmx.de
Wed May 31 07:27:39 EDT 2000
James Logajan <JamesL at Lugoj.Com> wrote:
>Speaking of interesting syntax, did you know the following is perfectly
>valid C/C++:
>
>var = 2["abc"];
>
>Points awarded for determining the type of "var" and the value assigned to
>it. Extra credit points for explaining why this is valid C/C++. (Hint: this
>has been valid C for as long as the language has been around.)
The magic of C pointer arithmetics makes a[i] equivalent to i[a], so
in the above var is of type char and has a value of 'c'.
Explanation:
After e.g. char a[] = "abc";
the following are true:
a == &a[0]
*a == a[0]
a + i == &a[i]
*(a + i) == a[i]
*(i + a) == a[i] == i[a]
The good thing about this is that nobody ever uses it,
except maybe in obfuscation contests.
Johannes
More information about the Python-list
mailing list