Dereference operator

Dereference operator

The dereference operator or indirection operator, denoted by "*" (i.e. an asterisk), is a unary operator found in C-like languages that include pointer variables. It operates on a pointer variable, and returns an l-value equivalent to the value at the pointer address. This is called "dereferencing" the pointer. For example, the C code

 int x = 0;
 int *pointer_to_x = &x;
 (*pointer_to_x) += 1;
 //x is now equal to 1

increments the variable x by using the indirection operator and a pointer to the variable x.

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 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 code

 int[] a = new int[]{1, 2, 3};
 int c = a.length;

first 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 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.

See also



Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • ! (disambiguation) — ! is a punctuation mark called an exclamation mark, exclamation point, ecphoneme, or bang. ! may also refer to: Contents 1 Mathematics and computers 2 Music 3 …   Wikipedia

  • Pointer (computing) — This article is about the programming data type. For the input interface (for example a computer mouse), see Pointing device. Pointer a pointing to the memory address associated with variable b. Note that in this particular diagram, the computing …   Wikipedia

  • Comparison of C Sharp and Java — The correct title of this article is Comparison of C# and Java. The substitution or omission of the # sign is because of technical restrictions. Programming language comparisons General comparison Basic syntax Basic instructions …   Wikipedia

  • Operators in C and C++ — This is a list of operators in the C and C++ programming languages. All the operators listed exist in C++; the fourth column Included in C , dictates whether an operator is also present in C. Note that C does not support operator overloading.… …   Wikipedia

  • Comparison of programming languages (mapping) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • C++0x — is the planned new standard for the C++ programming language. It is intended to replace the existing C++ standard, ISO/IEC 14882, which was published in 1998 and updated in 2003. These predecessors are informally known as C++98 and C++03. The new …   Wikipedia

  • C++ classes — For background information, see C++. The C++ programming language allows programmers to separate program specific datatypes through the use of classes. Instances of these datatypes are known as objects and can contain member variables, constants …   Wikipedia

  • Comparison of programming languages (object-oriented programming) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • Microsoft Macro Assembler — Developer(s) Microsoft Stable release 10.0.30319.1 / April 12, 2010; 18 months ago (2010 04 12) Operating system Microsoft Windows and MS DOS …   Wikipedia

  • Concepts (C++) — Concepts and the related notion of axioms were an extension to C++ s template system proposed for C++0x. They were designed to improve compiler diagnostics and to allow programmers to codify in the program some formal properties of templates that …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”