Offend Me
RSS Feed Twitter

2014-01-31 — Permalink

btw

I discovered my new favourite fact about my new favourite language recently. I suppose it should be obvious but I hadn't though about it in explicitly these terms.

Given:

char* myStringArray[] = {"Hello", "Goodbye", "Tomatoes"};
int index = 2;

then the following will print Tomatoes:

printf("%s
", myStringArray[index]);

and so (this is the bit I hadn't fully realised) will this:

printf("%s
", index[myStringArray]);

Good times :)

blog comments powered by Disqus