strlen与sizeof

来源:互联网 发布:windows官方主题 云 编辑:程序博客网 时间:2024/06/05 20:53

char strInput[7] = "ABCDEF"

char strInput[] = "ABCDEF";

   int i =  sizeof(strInput) ;

i的值为7


char *strInput = "ABCDEF"

   int i =  sizeof(strInput) ;

i的值为4
strInput为指针, sizeof(strInput) 返回的是指针的大小, 一般指针站4个字节


char strInput[] = "ABCDEF";

int i = strlen(strInput);
i的值为6 

会有警告 :从“size_t”转换到“int”,可能丢失数据


0 0
原创粉丝点击