Pointer
From Coderwiki
More actions
Pointers are not used too frequently in most high-level programming languages, but they are everywhere in lower-level programming.
The fundamental concept of both a pointer and a reference is to store a memory address to a variable or value.
Why are they needed?
edit edit sourceThe alternative to passing around pointers (known as pass by reference) is to pass the actual value to functions, known as pass by value. There are some issues with this:
- You end up with multiple copies of the same value, so mutating the original value is harder
- If the programming language needs to make a copy of the value, that requires memory allocation and is therefore slow.
References
edit edit sourceThe idea behind both pointers and references are very similar, but please see References for some subtle differences.