C find static array size

2019-06-15 14:05发布

问题:

static char* theFruit[] = {
    "lemon",
    "orange",
    "apple",
    "banana"
};

I know the size is 4 by looking at this array. How do I programmatically find the size of this array in C? I do not want the size in bytes.

回答1:

sizeof(theFruit) / sizeof(theFruit[0])

Note that sizeof(theFruit[0]) == sizeof(char *), a constant.



标签: c arrays static