Dereference operator
Encyclopedia
The dereference operator or indirection operator, denoted by "
), is a unary operator found in C
-like languages that include pointer variables. It operates on a pointer variable, and returns an
increments the variable
In BCPL
, an ancestor of C, the equivalent operator was represented using an exclamation mark
.
Many other operators exist to dereference pointers, and this is of significant importance especially in Object Oriented languages. In Java for example there is the binary operator, "dot," which is placed by infix notation
between an object reference on the left and a member of that object's class on the right. In the form
first creates an array of
The unary * operator, as defined in C
and C++
, can be used in compositions where multiple acts of dereferencing are required. Pointers can of course reference other pointers, and in such cases, multiple applications of the dereference operator are needed. Similarly, the Java dot operator can be used in compositions forming quite sophisticated statements that require substantial dereferencing of pointers behind the scenes during evaluation.
*
" (i.e. an asteriskAsterisk
An asterisk is a typographical symbol or glyph. It is so called because it resembles a conventional image of a star. Computer scientists and mathematicians often pronounce it as star...
), is a unary operator found in C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
-like languages that include pointer variables. It operates on a pointer variable, and returns an
l-valueValue (computer science)In computer science, a value is an expression which cannot be evaluated any further . The members of a type are the values of that type. For example, the expression "1 + 2" is not a value as it can be reduced to the expression "3"...
equivalent to the value at the pointer address. This is called "dereferencing" the pointer. For example, the C codeincrements the variable
x
by using the indirection operator and a pointer to the variable x
.In BCPL
BCPL
BCPL is a procedural, imperative, and structured computer programming language designed by Martin Richards of the University of Cambridge in 1966.- Design :...
, an ancestor of C, the equivalent operator was represented using an exclamation mark
Exclamation mark
The exclamation mark, exclamation point, or bang, or "dembanger" is a punctuation mark usually used after an interjection or exclamation to indicate strong feelings or high volume , and often marks the end of a sentence. Example: “Watch out!” The character is encoded in Unicode at...
.
Many other operators exist to dereference pointers, and this is of significant importance especially in Object Oriented languages. In Java for example there is the binary operator, "dot," which is placed by infix notation
Infix notation
Infix notation is the common arithmetic and logical formula notation, in which operators are written infix-style between the operands they act on . It is not as simple to parse by computers as prefix notation or postfix notation Infix notation is the common arithmetic and logical formula notation,...
between an object reference on the left and a member of that object's class on the right. In the form
X.Y
the dot operator dereferences the pointer X
, yielding an object, and then accesses the member Y
from that object. For example, the Java codefirst creates an array of
int
primitives, and stores a reference to that array in pointer a
. The dot operator is then used to dereference the pointer a
and access the length
member of the array object, storing the value in variable c
.The unary * operator, as defined in C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
and C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...
, can be used in compositions where multiple acts of dereferencing are required. Pointers can of course reference other pointers, and in such cases, multiple applications of the dereference operator are needed. Similarly, the Java dot operator can be used in compositions forming quite sophisticated statements that require substantial dereferencing of pointers behind the scenes during evaluation.