Array Indexing vs. The Cooler Pointer Arithmetic
Description
This image uses the 'Daniel vs. The Cooler Daniel' meme format, which consists of two side-by-side yearbook photos of the same person. The first, labeled 'Daniel', shows a standard, smiling portrait. The second, labeled 'The cooler Daniel', shows him wearing sunglasses and looking more suave. This format is used to compare two things, suggesting the second is a more stylish or sophisticated version of the first. In this tech-focused version, the code snippet 'a[i]=5' is superimposed over the first photo. This represents standard array bracket notation for element access, which is common and readable in many programming languages. Over the 'cooler Daniel' photo is the code '*(a+i)=5'. This represents pointer arithmetic, a more explicit way of accessing the same array element, common in languages like C and C++. In C/C++, these two syntaxes are functionally identical and compile to the same instructions. The humor lies in the developer in-joke that using explicit pointer arithmetic is a 'cooler', more hardcore, or more knowledgeable way to write code, even though it's less readable than the standard array notation. It pokes fun at the tendency among some programmers to favor more obscure or low-level syntax as a way of demonstrating technical prowess
Comments
34Comment deleted
Modern compilers see no difference between the two. Modern code reviewers, however, see a significant difference in the author's desire to collaborate
Sure, both compile to the same MOV instruction, but one of them makes the reviewer think you can read objdump output without coffee
The real cooler Daniel would've used a[i] = 5 with -O3 and let the compiler decide whether pointer arithmetic was actually faster, then spent the saved time arguing about move semantics in the code review
The real senior move is knowing that `a[i]` is literally just syntactic sugar for `*(a+i)` - the compiler generates identical assembly either way. But we all know the architect who insists on pointer arithmetic in code reviews because 'it shows you understand what's really happening,' while the rest of us are just trying to pass the readability bar and avoid off-by-one errors in production at 3 AM
Cooler Daniel thinks *(a+i)=5 is faster; the optimizer disagrees, but future-you debugging the inevitable off-by-one at 3am will remember who approved it
C defines a[i] as *(a+i); the optimizer emits identical assembly - only the PR nitpicks scale with the ‘coolness’
Pointer arithmetic: because who needs bounds checks when segfaults come with swagger?
Except for the MISRA violation Comment deleted
i[a]=5; Comment deleted
Yesssssss Comment deleted
5=i[a]; Comment deleted
And now this is an error Comment deleted
Unfortunately yes Comment deleted
this is not what commutative property states Comment deleted
but you can overload "=" to make it work Comment deleted
i'm not sure about operator overloading in C Comment deleted
nobody said it is. *(a+i) works in C++ too Comment deleted
yeah. forgot about it Comment deleted
ah, I see, the Yoda notation... Comment deleted
NULL[a + i] = 5 Comment deleted
error: array subscript is not an integer Comment deleted
yeah Comment deleted
another way is casting NULL to size_t Comment deleted
nah, casting isnt interesting for me Comment deleted
XD Comment deleted
but it will work with 0[a+i]... Comment deleted
Satan laughs in C/C++ Comment deleted
Is *(a+i) more efficient than a[i]? I thought they are absolutely same Comment deleted
they're the same Comment deleted
Ok, thanks. That meme made me doubt Comment deleted
imho a[i] could be more efficient Comment deleted
Why so? Comment deleted
Foot gun? More like foot cannon! Comment deleted
I forgot Comment deleted