开发者

How to cast an int's address to char pointer in C?

Currently the below code gives me a wa开发者_如何学Pythonrning when i try to compile it:

int z; char *w;

w = &z;

How can i cast &z properly so that w stores the pointer to z's address?


Try:

w = (char*) &z;


Don't forget that generally casting pointers in C is a bad idea. Sure, there are some times when it is the right thing to do, but we can't see exactly what you're doing here. In most cases there is a better, more portable way to do whatever it is which you are aiming at here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜