void指针问题
#include <stdio.h>#include <string.h>
int main(void)
{
char src[] = "******************************";
char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
char *ptr;
printf("destination before memcpy: %s\n", dest);
ptr = memcpy(dest, src, strlen(src));
if (ptr)
printf("destination after memcpy:%s\n", dest);
else
printf("memcpy failed\n");
return 0;
}
这段代码报错的原因是什么啊, 我这里正常 #include <stdio.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
char src[] = "******************************";
char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
char *ptr;
printf("destination before memcpy: %s\n", dest);
ptr =(char*) memcpy(dest, src, strlen(src));
if (ptr)
printf("destination after memcpy:%s\n", dest);
else
printf("memcpy failed\n");
return 0;
}
这个意思吗? memcpy的返回值类型是void *,赋值时类型要匹配,否则编译报错
页:
[1]