简体   繁体   中英

How to cast a void pointer to an int?

I have a void* pointer . I want to cast the value at that pointer to an int and add it the value at another void* x . I have already tried:

x += (int)(*pointer);

But this gives me a operand of type 'void' where arithmetic or pointer type is required error

You can't dereference a pointer to void. That would return a value of type void , which doesn't exist.

You have to cast the pointer to an int* , then dereference that.

x += *(int*)pointer;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM