关于#c语言#的问题:自定义函数里面读取字符数组指针,然后我想要用sizeof(string)/sizeof(string[0]计算数组的长度

自定义函数里面读取字符数组指针,然后我想要用sizeof(string) / sizeof(string[0]计算数组的长度。然后我在主函数里面也打印了sizeof(string) / sizeof(string[0],最后发现他们的结果不一样,这是为什么呀?

#include 
int CountNumofLetter(char* string)
{
    int i = 0, count = 0;
    for (i = 0; i < sizeof(string) / sizeof(string[0]); i++)
    {
        if (string[i] >= 'A' && string[i] <= 'Z' || string[i] >= 'a' && string[i] <= 'z')
            count += 1;

    }
    printf("%d\n", sizeof(string) / sizeof(string[0]));
    return count;
}

int main ()
{
    char string[10] = "aaacv12AS";
    printf("%d\n", sizeof(string) / sizeof(string[0]));

    printf("%d", CountNumofLetter( string));
    return 0;

}


img


你传进去的是指针,已经不能按照数组方法去计算大小啦,望采纳