How to: Obtain the Value of a Pointer Variable (C# Programming Guide)


Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

Use the pointer indirection operator to obtain the variable at the location pointed to by a pointer. The expression takes the following form, where p is a pointer type:


You cannot use the unary indirection operator on an expression of any type other than the pointer type. Also, you cannot apply it to a void pointer.

When you apply the indirection operator to a null pointer, the result depends on the implementation.

In the following example, a variable of the type char is accessed by using pointers of different types. Note that the address of theChar will vary from run to run, because the physical address allocated to a variable can change.

// compile with: /unsafe

unsafe class TestClass
    static void Main()
        char theChar = 'Z';
        char* pChar = &theChar;
        void* pVoid = pChar;
        int* pInt = (int*)pVoid;

        System.Console.WriteLine("Value of theChar = {0}", theChar);
        System.Console.WriteLine("Address of theChar = {0:X2}",(int)pChar);
        System.Console.WriteLine("Value of pChar = {0}", *pChar);
        System.Console.WriteLine("Value of pInt = {0}", *pInt);

Value of theChar = Z
Address of theChar = 12F718
Value of pChar = Z
Value of pInt = 90

C# Programming Guide
Pointer Expressions
Pointer types
fixed Statement