[b][size=large][align=center]C++ 'void*' convert to 'int'[/align][/size][/b]
The code as following:
[code = "c++"]
#include<iostream>
using namespace std;
int main(void)
{
int a = 1;
void * v102;
v102 = new int[11];
[color=red] ((int *)v102)[9] = (int )a;[/color]
cout << ((int *)v102)[9] << endl;
return 0;
}
[/code]
This is ((int *)v102)[9] = (int )a;but not (int *)v102[9] = (int)a;
void * v102;doesn't define the size of the pointer,so we must assign the size when we use the void pointer.
The code as following:
[code = "c++"]
#include<iostream>
using namespace std;
int main(void)
{
int a = 1;
void * v102;
v102 = new int[11];
[color=red] ((int *)v102)[9] = (int )a;[/color]
cout << ((int *)v102)[9] << endl;
return 0;
}
[/code]
This is ((int *)v102)[9] = (int )a;but not (int *)v102[9] = (int)a;
void * v102;doesn't define the size of the pointer,so we must assign the size when we use the void pointer.