using System;
using System.Collections.Generic;
using System.Text;
namespace AddressOfVariable
{
class Program
{
class Point
{
public int x;
public int y;
}
static void Main(string[] args)
{
int number;
//获取栈上变量的地址
unsafe
{
int* p = &number;
*p = 0xffff;
Console.WriteLine("{0:x}", *p);
Console.WriteLine("Address of numbe:0x{0:x}", (int)p);
}
string message = "Hello World!";
//获取堆上变量的地址
unsafe
{
fixed (char* p = message)
{
Console.WriteLine("Address of message 0x{0:x}", (int)p);
}
}
Point point = new Point();
//获取堆上变量的地址
unsafe
{
fixed (int* p = &point.x)
{
Console.WriteLine("Address of point 0x{0:x}", (int)p);
}
}
}
}
}
相关文章
- 04-23awk使用shell变量,shell获取awk中的变量值
- 04-23【Teradata DSQL】获取env中的用户和口令到变量中(无需落地到文件中)
- 04-23Vue-cli项目axios+require动态获取后台数据库的图片地址
- 04-23vue中通过变量名的字符串,来获取变量并使用
- 04-23lua-将请求参数里url的地址获取到后进行重定向
- 04-23从Android中的地址获取纬度,经度
- 04-23C – 如何在lldb / Xcode中获取std :: vector对象的地址
- 04-23火狐mozilla官方ftp站点获取旧版本火狐的下载地址
- 04-23c-以十进制打印变量的地址
- 04-23获取客户端访问的ip地址