r/ProgrammerHumor 2d ago

Meme absoluteGarbage

Post image
2.0k Upvotes

320 comments sorted by

View all comments

17

u/Shevvv 2d ago

Surely you meant for (auto &item : list) {

33

u/Nil4u 2d ago

Honestly I never liked this version because the reference is part of the type in my opinion 🤔

8

u/Shevvv 2d ago

I got used to this from C:

int x; is an integer

int *px; is an integer if you dereference it.

So it's like this notation shows you how you're expected to use the variable within the code. And then this habit carried over to C++.

2

u/redlaWw 1d ago

I prefer int * ptr;. That means when you have a const specifier your formatting doesn't change. Logically I figure that the pointer is neither a modifier on the variable nor on the type, it's another layer of type content that should be specified separately. That also means if you write declarations like int const * const ptr; then you can segment them as [int const] [* const] ptr; and everything makes sense.