+ 4
What is the difference between a reference and a pointer?
2 odpowiedzi
+ 2
A pointer is a whole variable that's job is literally to just hold the reference of something.
A reference is an object that, when passed as an argument (to methods and functions requesting references) can be manipulated by them globally.
For example:
#include <iostream>
int myVar = 3;
int *myPtr = &myVar;
std::cout << myPtr << std::endl; // Prints the value
std::cout << *myPtr; // Prints the memory location, useful for low-level business
0
A reference is an address
While A Pointer holds a reference