开发者

Treating an int as an address/pointer

I have a C function that returns an int that represents the 开发者_StackOverflow社区base address of some block in memory. If I wanted to treat the value of that int as an address (so that I could treat it as an array or otherwise traverse the area in memory it points to) what syntax would I use?


Assuming ints and pointers are the same size on your machine a simple cast should work.

For example:

int function_that_returns_address();
...
char * p = (char *) function_that_returns_address();
p[0] = 'H';
p[1] = 'i';
p[2] = 0;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜