开发者

Treating an int as an address/pointer

开发者 https://www.devze.com 2023-03-03 23:58 出处:网络
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 trea

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

精彩评论

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