O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

29.6. Using the & address-of operator

The & symbol is used as the binary AND operator when placed between two numbers, or the logical (boolean) AND operator when placed between two boolean values. But when used in unsafe codes, & becomes the 'address-of' operator.

Let's look at the following two statements:

10: int myInt = 3;
11: int* pInt = &myInt;

&myInt means 'the address of myInt'. What is happening is that the address of this int variable is being assigned to be stored in pointer pInt. Since an address is simply a number, you can do something like this in C#:

int* pAny = (int*)0x123456;

but statements like the one above are senseless and dangerous unless you are certain of what is stored at 0x123456.

When you create a variable and assign ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required