It should also be mentioned that the code isn't guaranteed to work if the variables hadn't been allocated on the stack. If it uses a real object that is allocated on the heap:
public unsafe void Test() {
string x = 42.ToString();
string* px = &x; // Dangerous!
*px += 1;
Console.Write(*px);
}
The variable x is still allocated on the stack, but it is a reference to a string object that is allocated on the heap. If you copy the reference to a pointer, you will get the current location of the string in memory, but as the garbage collector can move objects in the heap, there is no guarantee that the string will stay in that location. It can be moved to another location at any moment, and the garbage collector will update the reference x to point to the new location, but it will not update the pointer px.
--- single minded; short sighted; long gone;