Question Of The Day !!!! -- (27-05-2005)
Reply
![]() |
|
From:
![]() surya27681
|
Pointer types (C# Programmers Reference) In an unsafe context, a type may be a pointer type as well as a value type or a reference type. A pointer type is declared as an unmanaged type or void. The declaration takes one of the following forms:
unmanaged type* identifier; void* identifier; Parameters unmanaged type
One of the following:
sbyte, byte, short, ushort, int, uint, long, ulong, char, float, double, decimal, or bool.
Any enum type.
Any pointer type.
Any user-defined struct type that contains fields of unmanaged types only.
identifier The pointer variable name.
Remarks Pointer types do not inherit from object and no conversions exist between pointer types and object. Also, boxing and unboxing do not support pointers. However, you can convert between different pointer types and between pointer types and integral types.
When you declare multiple pointers in the same declaration, the * is written along with the underlying type only, not as a prefix to each pointer name. For example:
int* p1, p2, p3; // Ok int *p1, *p2, *p3; // Invalid in C# A pointer cannot point to a reference or to a struct that contains references because the garbage collector doesn't know anything about pointers, but does about references.
The value of the pointer variable of type myType* is the address of a variable of type myType. The following are examples of pointer type declarations:
Example Description int* p p is a pointer to an integer int** p p is a pointer to pointer to an integer int*[] p p is a single-dimensional array of pointers to integers char* p p is a pointer to a char void* p p is a pointer to an unknown type
The pointer indirection operator * can be used to access the contents at the location pointed to by the pointer variable. For example, for the following declaration,
int* myVariable; the _expression_ *myVariable denotes the int variable found at the address contained in myVariable.
You cannot apply the indirection operator to a pointer of type void*. However, you can use a cast to convert a void pointer to any other pointer type, and vice versa.
A pointer can be null. Applying the indirection operator to a null pointer results in an implementation-defined behavior.
Be aware that passing pointers between methods can cause undefined behavior. Examples are returning a pointer to a local variable via an Out or Ref parameter or as the function result. If the pointer was set in a fixed block, the variable to which it points may no longer be fixed.
The following table lists the operators and statements that can operate on pointers in an unsafe context:
Operator/Statement Use * to perform pointer indirection. -> to access a member of a struct through a pointer. [] to index a pointer. & to obtain the address of a variable. ++ and -- to increment and decrement pointers. + and - to perform pointer arithmetic
|
|
View other groups in this category.
![]() |
To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings.
Need help? If you've forgotten your password, please go to Passport Member Services.
For other questions or feedback, go to our Contact Us page.
If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list.
Remove my e-mail address from dotNET User Group Hyd.
|
|