+ 2
What is the difference between int and int& in C++
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)?
+ 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.