void *p;int *int_ptr = p;
这在 c 中可以正常工作。现在,如果我们使用 malloc() 来分配一些内存空间,我们可以使用显式类型转换,但如果我们不这样做,也没问题。the malloc()函数返回空指针。
int *int_ptr = malloc(sizeof(int) * 10);
这里返回的void指针隐式转换为整数类型指针。
现在如果我们想在c和c++中运行相同的程序,我们应该显式类型转换指针。
void *p;int *int_ptr = (int *) p;int *arr_ptr = (int *) malloc(sizeof(int) * 10);
以上就是在c和c++中,“void *”有什么区别?的详细内容。