先上代码:
#include <stdio.h>
#include <string.h> const char g_ip[] = "";
int func1(const char *ip)
{
printf("ip:%s\n",ip);
printf("ip size:%d\n",sizeof(ip));
if(*ip == '\0')
printf("ip is none\n");
printf("g_ip:%s\n",g_ip);
printf("g_ip size:%d\n",sizeof(g_ip));
if(*ip == '\0')
printf("g_ip is none\n");
return ;
} int main()
{
const char ip[]="ABCDEFG";
func1(ip);
return ;
}
运行结果:
[zyc@localhost ~]$ ./a.out
ip:ABCDEFG
ip size:
g_ip:
g_ip size:
看8、9行代码,为什么ip是一个char指针, 但是%s的时候却知道到底要printf多长???