A pointer is a special type of data type. Instead of storing data, it stores a memory location. At this location is the data.
In some languages, like C/C++, they expect the programmer to track and maintain the pointer information, using special references to know if they are storing/retrieving a location for data, or accessing the data itself. This can be fairly confusing, and be hard to debug.
In C/C++, you use a * (star/asterisk) before a variable name to specify that you are using a pointer. Specifically, you are using the data at the location stored at the variable’s location. You can use the & (ampersand) to get the memory location of a variable.
int myVar= 32; // actual variable declaration
int *ip; // pointer variable declaration
ip = &myVar; // store address of var in pointer variable
In most modern languages (C#, Java, PHP, JavaScript), pointer handling is hidden from the developer, and there is a change in term to a reference. Most commonly when you have a user defined data type or use the new keyword, it will automatically create a reference for you.
References and pointers are very similar, in fact, you could think of a reference as a “super pointer”, in that the OS and Language runtime manages the pointer for you. The location of your variables may change during runtime as the runtime system determines it needs more memory, or a larger block of free memory. The data is moved and the reference is then automatically updated, so it points at a new location without interaction of the developer being needed.
Additionally references tend to be cleaned up by the system as they are no longer being used. This reduces the number of memory leaks, in theory, as you don’t have to manage the destructor of your objects – like you do in C/C++.
Pointers and References was originally found on Access 2 Learn