#include <iostream>
using namespace std;
int main() {
void* p1;
int a = 5;
p1 = &a; //将a的地址赋值给p1;(地址在不断变化
int* p2 = static_cast<int*>(p1); //强制类型显性转换,将void指针p1的指向的地址转换成int类型指针,并赋值给p2指针;
// cout << "p1=" << *p1 << endl; 错误!p1是void指针,非完整对象类型,无法输出;
cout << "p2=" << *p2 << endl;
return 0;
}
12-13
5344
10-27
3万+
12-21
5749