在线运行代码链接

#include <stdio.h>
#include <string.h>

int main()
{
    char str[] = "This is string";
    printf("%s %lu\n", str, strlen(str));       
    
    //找该字符串尾0所在的位置
    int count = -1;
    while(str[count+1])
        count++;
    printf("count is %d\n", count);     //下标为count+1为尾0
    
    printf("sizeof str = %ld\n", sizeof (str));
    
    char *pch = str;
    
    sprintf(pch, "%i", 1);
    
    printf("%s %lu\n", str, strlen(str));
    
    //找该字符串尾0所在的位置
    count = -1;
    while(str[count+1])
        count++;
    printf("count is %d\n", count); //该结果说明 sprintf 函数自动在格数输出后补尾0:https://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm
    
    printf("sizeof str = %ld\n", sizeof (str));

    return 0;
}