this post was submitted on 03 May 2024
237 points (94.1% liked)

Programmer Humor

32495 readers
283 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

Alt text:

Image that says:

HOLY SHIT!! IS THAT A MOTHERF*CKING C++ REFERENCE???

int& a = b;

you are viewing a single comment's thread
view the rest of the comments
[–] xmunk@sh.itjust.works 15 points 6 months ago* (last edited 6 months ago)

In my experience, it's rare to see int& in day to day as a regular old lvalue... it essentially just allows you to alias a variable to another name. It's much more common to see them used in function parameters to leverage pass by reference. In C++ pointers usually aren't particularly useful compared to just passing things by reference since stack variables get auto-gc'd it's the preferred style of frameworks like Qt and is extremely easy to use.

Here's a breakdown if you want more information https://en.cppreference.com/w/cpp/language/reference