The meaning of *
is dependent on context. When in a data or function argument declaration, it is a datatype qualifier, not an operator int*
is a datatype in itself. For this reason it is useful perhaps to write:
int* x ;
rather than:
int *x ;
They are identical, but the first form emphasises that it the *
is part of the type name, and visually distinguishes it from usage as dereference operator.
When applied to an instantiated pointer variable, it is the dereference operator, and yields the the value pointed to.
&
in C is only an operator, it yields the address (or pointer to) of an object. It cannot be used in a declaration. In C++ it is a type qualifier for a reference which is similar to a pointer but has more restrictive behaviour and is therefore often safer.
Your suggestion in the comment here:
funct(&a) // Sends an address of a pointer
is not correct. The address of a
is passed; that would only be "address of a pointer" is a
itself is a pointer. A pointer is an address. The type of an address of a pointer to int
would be int**
(a pointer to a pointer).
Perhaps it is necessary to explain the fundamentals of pointer and value variables? A pointer describes the location in memory of a variable, while a value describes the content of a memory location.
<typename>
*
is a pointer-to-<typename>
data type.
&
*<value-variable>
yields the address or location of <variable>
(i.e. a pointer to <variable>
),
*
*<pointer-variable>
dereferences a pointer to yield the the value at the address represented by the pointer.
So given for example:
int a = 10 ;
int* pa = &a ;
then
*pa == 10