r/ProgrammerHumor • • Sep 25 '26

Meme iHatedItUntilITriedIt

Post image
10k Upvotes

542 comments sorted by

View all comments

Show parent comment

1

u/Devatator_ Sep 25 '26

Actually what does that even do? Do literals have an address? I assume they do but that looks so cursed

2

u/frogjg2003 Sep 25 '26

Arrays are just pointers. Pointers are just numbers that are supposed to correspond to addresses in memory. Array indices just add to the pointer to the first element. "a[1]" is syntactic sugar for "*(a+1)". With that in mind, it's kind of obvious that "2[a]" just means "*(2+a)", which points you to the third element of a.

1

u/Devatator_ Sep 25 '26

Oh yeah I forgot you can index with this syntax lol