Quick summary: there is data and there is a reference to the location of that data (also known as a pointer).
A pointer is a number which is a location in the stack. The stack is a chunk of memory that is allocated to the application either through memory or virtual memory (hard disk). So if your pointer value is 1000 then the data for the object starts at location 1000 of the stack. The value stored at that pointer can change while the pointer value remains 1000. It could be one byte, or 1000 bytes. Referencing allows you to interact with one instance of a value from multiple places. For example you could have 2 threads running that are doing 2 different tasks in a loop. You can pass a reference to a value that will shut down the threads when the application is closing something like this:
bool bShutdownSignal = false;
startThreadOne(&bShutdownSignal);
startThreadTwo(&bShutdownSignal);
If at any time bShutdownSignal is set to true both threads could read the value and shut down. Now if you passed by copy there would be 3 different pointers to bShutdownSignal and as such 3 potentially different values.
119 views
Usually answered in minutes!
×