一些练习题
题一
char *ptr = "hello world";
printf("sizeof(ptr) = %ld\n",sizeof(ptr)); //测量的是ptr指针变量的结果
printf("strlen(ptr) = %ld\n",strlen(ptr));
结果:
sizeof(ptr) = 8
strlen(ptr) = 11
题二
char *s1 = "hello world";
char s2[100] = "hello world";
printf("sizeof(s1) = %ld\n", sizeof(s1));
printf("sizeof(s2) = %ld\n", sizeof(s2));
printf("strlen(s1) = %ld\n", strlen(s1));
printf("strlen(s2) = %ld\n", strlen(s2));
求以上四个的输出结果。
结果:
sizeof(s1) = 8
sizeof(s2) = 100
strlen(s1) = 11
strlen(s2) = 11