自定义函数里面读取字符数组指针,然后我想要用sizeof(string) / sizeof(string[0]计算数组的长度。然后我在主函数里面也打印了sizeof(string) / sizeof(string[0],最后发现他们的结果不一样,这是为什么呀?
#include <stdio.h>
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;
}