(3)将(2)中得到的地址转换为int类型
下面贴出code,几行的事儿,但可以深深的吸引着我们的脑洞:
// ptrtest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
using namespace std;
int add(int a,int b){
char * c;
c = reinterpret_cast<char*>(a);
char * d=&c[b];
int sum=reinterpret_cast<int>(d);
return sum;
}
int _tmain(int argc, _TCHAR* argv[])
{
cout <<"sum =" <<add(4,5) << endl;
return 0;
}
让我们欣赏一下watch窗口,顿时脑洞打开吧!
原文地址:http://blog.csdn.net/gggg_ggg/article/details/47999851