+ 2

What is the difference between int and int& in C++

18th Jul 2018, 4:43 AM
Tevin Charles
Tevin Charles - avatar
2 Respuestas
+ 3
int& is the reference of the int (like 0x22ccec...). it's very usefull for speed and low use of ram in a program thanks to pointers. for example you can't pass an array in a function, but you can pass its reference... it's better/lighter send your whole home, or only its address (reference)?
18th Jul 2018, 6:45 AM
Yuri Biasi
Yuri Biasi - avatar
+ 2
int& is a reference to int variable. Reference is something very close to the pointer. The main difference is that the reference is constant, so it should be assigned immediately after initialization and you can do no pointer arithmetics with reference.
18th Jul 2018, 5:03 AM
Дмитро Іванов
Дмитро Іванов - avatar