Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Official names for pointer operators

Tags:

c++

pointers

What are the official names for the operators * and & in the context of pointers? They seem to be frequently called dereference operator and address-of operator respectively, but unfortunately, the section on unary operators in the standard does not name them.

I really don't want to name & address-of anymore, because & returns a pointer, not an address. (see below) The standard is very clear about this:

The result of the unary & operator is a pointer to its operand.

Symmetry suggests to name & reference operator which is a little unfortunate because of the collision with references in C++. The fact that & returns a pointer suggests pointer operator. Are there any official sources that would confirm these (or other) namings?

pointers vs. addresses

A pointer is a language mechanism, while an address is an implementation detail. Addresses are untyped, while pointers aren't, except for void*. Kevlin Henney also distinguishes between pointers and addresses in an Interview:

C [...] allows us to abstract the specifics of the machine to the point that we are talking about pointers and not addresses. There is a whole load of pain that you no longer have to go through.

like image 911
fredoverflow Avatar asked Mar 21 '10 20:03

fredoverflow


People also ask

What is the other name for pointer operator?

C++ provides two pointer operators, which are Address of Operator (&) and Indirection Operator (*). A pointer is a variable that contains the address of another variable or you can say that a variable that contains the address of another variable is said to "point to" the other variable.

What is the arrow operator called?

The (->) arrow operator The -> is called the arrow operator. It is formed by using the minus sign followed by a greater than sign. Simply saying: To access members of a structure, use the dot operator. To access members of a structure through a pointer, use the arrow operator.

What are the operators in pointers?

You can use the following operators to work with pointers: Unary & (address-of) operator: to get the address of a variable. Unary * (pointer indirection) operator: to obtain the variable pointed by a pointer. The -> (member access) and [] (element access) operators.


1 Answers

From the C99 draft, at the index:

* (indirection operator), 6.5.2.1, 6.5.3.2

& (address operator), 6.3.2.1, 6.5.3.2

From the C++0x draft, at the index:

*, see indirection operator, see multiplication operator

&, see address-of operator, see bitwise AND operator

It's also referenced in 9.6/3 "The address-of operator & shall not be applied to a bit-field, so there are no pointers to bit-fields."

(So, sorry, you still need to call & "address-of" :p)

Personally I don't care the actual name as long as other can understand what I'm saying. I just call * "star" and & "and". :)

like image 107
kennytm Avatar answered Sep 28 '22 06:09

kennytm