C# LANGUAGE SPECIFICATION
In an unsafe context, a type (§4) may be a pointer-type as well as a value-type or a reference-type.
type: value-type reference-type pointer-type
A pointer-type is written as an unmanaged-type or the keyword void, followed by a * token:
pointer-type: unmanaged-type * void *
The type specified before the * in a pointer type is called the referent type of the pointer type. It represents the type of the variable to which a value of the pointer type points.
Unlike references (values of reference types), pointers are not tracked by the garbage collector—the garbage collector has no knowledge of pointers and the data to which they point. For this reason a pointer is not permitted to point to a reference or to a struct that contains references, and the referent type of a pointer must be an unmanaged-type.
An unmanaged-type is any type that isn’t a reference-type and doesn’t contain reference-type fields at any level of nesting. In other words, an unmanaged-type is one of the following:
sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
Any user-defined struct-type that contains fields of unmanaged-types only.
The intuitive rule for mixing of pointers and references is that referents of references (objects) are permitted to contain pointers, but referents of pointers are not permitted to contain references.
Some examples of pointer types are given in the table below:
Pointer to byte
Pointer to char
Pointer to pointer to int
Single-dimensional array of pointers to int
Pointer to unknown type
For a given implementation, all pointer types must have the same size and representation.
Unlike C and C++, when multiple pointers are declared in the same declaration, in C# the * is written along with the underlying type only, not as a prefix punctuator on each pointer name. For example
int* pi, pj;// NOT as int *pi, *pj;
The value of a pointer having type T* represents the address of a variable of type T. The pointer indirection operator * (§18.5.1) may be used to access this variable. For example, given
318Copyright Microsoft Corporation 1999-2003. All Rights Reserved.