How to

get pointer to value

Published: 15. January 2009 | Updated: 15. January 2009
License: Microsoft Public License (MS-PL)
Categories: Framework » Unsafe Code
Tags: C# Unsafe
Was this snippet helpful for you? YESYES / NONO
// assign value to variable
int a = 10;

// create pointer to variable
int* p = &a;

// write value of variable
Console.WriteLine(a);

// write address of variable (hexadecimal)
Console.WriteLine("{0:X}", (int)p);
Console Output:
10
44CECC8
Send us feedback about this snippet »



Related Snippets: