H
howa
int i = 10;
void *j = &i;
How to print out the integer "10" ?
Thanks.
void *j = &i;
How to print out the integer "10" ?
Thanks.
#include <iostream>howa said:int i = 10;
void *j = &i;
How to print out the integer "10" ?
Echo?Alf said:* howa:
#include <iostream>
int main
{
std::cout << "10" << std::endl;
}
int i = 10;
void *j = &i;
How to print out the integer "10" ?
Echo?
* howa:
Technically the answer is to cast the pointer and dereference it,
*static_cast<int*>(j).
However, as a novice you should not use raw pointers at all, much less
void* pointers: what's the problem you're trying to use void* to solve?
It's harder to search for in code and more likely to hide errors (thehowa said:How does the following one compare with static_cast?
e.g. cout<< *(int*)j;
It's harder to search for in code and more likely to hide errors (the
compiler will reject inappropriate use of static_cast).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.