是否可以在C编程语言中取消引用void指针而不使用类型转换?
另外,有没有任何方法可以概括一个可以接收指针并将其存储在void指针中的函数,并且通过使用该void指针,我们可以创建一个通用函数吗?
例如:
void abc(void *a, int b)
{
if(b==1)
printf("%d",*(int*)a); // If integer pointer is received
else if(b==2)
printf("%c",*(char*)a); // If character pointer is received
else if(b==3)
printf("%f",*(float*)a); // If float pointer is received
}
Run Code Online (Sandbox Code Playgroud)
我想在不使用if-else语句的情况下使这个函数变得通用 - 这可能吗?
此外,如果有很好的互联网文章解释了无效指针的概念,那么如果你能提供这些URL会很有用.
是否可以使用void指针进行指针算术?