为什么函数strlen()对于两个字符数组的相同长度返回不同的值?

问题描述 投票:0回答:1
#include <stdio.h>
#include<string.h>

int main() {

    char a[50],b[50];// same sized arrays

    for(int j =0;j<50;j++){
        b[j]='b';a[j]='a';// initializing with the same number of elements
    }

    printf("the size of a is %ld,",strlen(a));
    printf("the size of B is %ld",strlen(b));

    return 0;
}

输出为

a的大小是50,B的大小是54

但是我期望的是a的大小是50B的大小是50

这里是什么问题?

c arrays strlen
1个回答
0
投票

这里是什么问题?

© www.soinside.com 2019 - 2024. All rights reserved.