C++ void* convert to int

C++ 'void*' convert to 'int'


The code as following:
[code = "c++"]
#include<iostream>
using namespace std;
int main(void)
{
   int a = 1;
   void * v102;
   v102 = new int[11];
  ((int *)v102)[9] = (int )a;  
   cout << ((int *)v102)[9]  << endl;
   return 0;
}


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.

你可能感兴趣的:(C++,c,C#)