strlen and sizeof

来源:互联网 发布:数据记录表 编辑:程序博客网 时间:2024/05/01 00:06

Given:

#include<stdio.h> int main() {    char s1[] = { 'M', 'y', 'W', 'o', 'r', 'd' };    char s2[] = "MyWord";    printf("%d %d\n",strlen(s1),strlen(s2));//random num  6    printf("%d %d\n",sizeof(s1),sizeof(s2));//7           7    return 0; }


ANSWER:
strlen: not including \0;
random a number cuz s1 is not a string, searching until \0;
try char s1[] = { 'M', 'y', 'W', 'o', 'r', 'd','\0'},strlen returns 6;
sizeof: including \0;

原创粉丝点击