engledow.me

Steve Engledow: Senior Solutions Builder at Amazon Web Services

Latest post: git-get — Latest project: git-cube

31 January 2014

btw

tags: code, c

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 :)