Twitter RSS Feed
Offend Me Blog

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\n", myStringArray[index]);

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

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

Good times :)

Tags: Blog

blog comments powered by Disqus