How to

change value through pointer

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;

// change value through pointer
*p = 15;

// write original variable
Console.WriteLine(a);

// write pointer value
Console.WriteLine(*p);
Console Output:
15
15
Send us feedback about this snippet »



Related Snippets: