The Full Wiki

More info on Dereference operator

Dereference operator: Wikis


Note: Many of our articles have direct quotes from sources you can cite, within the Wikipedia article! This article doesn't yet, but we're working on it! See more info or our list of citable articles.


From Wikipedia, the free encyclopedia

The dereference operator or indirection operator, denoted by "*" (i.e. an asterisk; often referred to as star), 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.

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 C language star operator 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


Got something to say? Make a comment.
Your name
Your email address