Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Pointer (computer programming)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Object which stores memory addresses in a computer program}} {{Other uses|Pointer (disambiguation)}} {{more citations needed|date=April 2018|reason=Many sections without any references}} {{Quote box|quote=I do consider [[Assignment (computer science)|assignment statements]] and pointer variables to be among computer science's "most valuable treasures."|width=33%|source=[[Donald Knuth]], ''Structured Programming, with go to Statements''<ref>{{cite journal|author=[[Donald Knuth]] |title=Structured Programming with go to Statements |journal=Computing Surveys |volume=6 |issue=5 |year=1974 |url=http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf |pages=261β301 |doi=10.1145/356635.356640 |url-status=dead |archive-url=https://web.archive.org/web/20090824073244/http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf |archive-date=August 24, 2009 |citeseerx=10.1.1.103.6084 |s2cid=207630080}}</ref>}} [[File:Pointers.svg|thumb|A pointer '''a''' pointing to the memory address associated with a variable '''b,''' i.e., '''a''' contains the memory address 1008 of the variable '''b'''. In this diagram, the computing architecture uses the same [[address space]] and [[#Formal description|data primitive]] for both pointers and non-pointers; this need not be the case.]] In [[computer science]], a '''pointer''' is an [[object (computer science)|object]] in many [[programming language]]s that stores a [[memory address]]. This can be that of another value located in [[computer memory]], or in some cases, that of [[memory-mapped I/O|memory-mapped]] [[computer hardware]]. A pointer ''references'' a location in memory, and obtaining the value stored at that location is known as ''dereferencing'' the pointer. As an analogy, a page number in a book's index could be considered a pointer to the corresponding page; dereferencing such a pointer would be done by flipping to the page with the given page number and reading the text found on that page. The actual format and content of a pointer variable is dependent on the underlying [[computer architecture]]. Using pointers significantly improves [[Computer performance|performance]] for repetitive operations, like traversing [[Collection (abstract data type)#Linear collections|iterable]] data [[Data structure|structures]] (e.g. [[String algorithms|strings]], [[lookup table]]s, [[control table]]s, [[Linked list|linked lists]], and [[Tree (data structure)|tree]] structures). In particular, it is often much cheaper in time and space to copy and dereference pointers than it is to copy and access the data to which the pointers point. Pointers are also used to hold the addresses of entry points for [[system call|call]]ed subroutines in [[procedural programming]] and for run-time linking to [[Dynamic link library#Explicit run-time linking|dynamic link libraries (DLLs)]]. In [[object-oriented programming]], [[Function pointer|pointers to functions]] are used for [[Name binding|binding]] [[method (computer programming)|methods]], often using [[virtual method table]]s. A pointer is a simple, more concrete implementation of the more abstract ''[[reference (computer science)|reference]]'' [[data type]]. Several languages, especially [[low-level programming language|low-level languages]], support some type of pointer, although some have more restrictions on their use than others. While "pointer" has been used to refer to references in general, it more properly applies to [[data structures]] whose [[Application programming interface|interface]] explicitly allows the pointer to be manipulated (arithmetically via ''{{vanchor|pointer arithmetic}}'') as a memory address, as opposed to a [[magic cookie]] or [[capability-based security|capability]] which does not allow such.{{Citation needed|date=May 2009}} Because pointers allow both protected and unprotected access to [[Memory address|memory addresses]], there are risks associated with using them, particularly in the latter case. Primitive pointers are often stored in a format similar to an [[integer]]; however, attempting to dereference or "look up" such a pointer whose value is not a valid memory address could cause a program to [[Crash (computing)|crash]] (or contain invalid data). To alleviate this potential problem, as a matter of [[type safety]], pointers are considered a separate type parameterized by the type of data they point to, even if the underlying representation is an integer. Other measures may also be taken (such as [[Data validation and reconciliation|validation]] and [[bounds checking]]), to verify that the pointer variable contains a value that is both a valid memory address and within the numerical range that the processor is capable of addressing.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)