C找到静态数组大小
static char* theFruit[] = { "lemon", "orange", "apple", "banana" };
通过查看这个数组,我知道大小是4。 如何以编程方式在C中查找此数组的大小? 我不希望大小以字节为单位。
sizeof(theFruit) / sizeof(theFruit[0])
注意sizeof(theFruit[0]) == sizeof(char *)
,一个常量。
static char* theFruit[] = { "lemon", "orange", "apple", "banana" };
通过查看这个数组,我知道大小是4。 如何以编程方式在C中查找此数组的大小? 我不希望大小以字节为单位。
sizeof(theFruit) / sizeof(theFruit[0])
注意sizeof(theFruit[0]) == sizeof(char *)
,一个常量。