0

尝试了解如何在 C 和 C++ 中获取 char* numberlist[] 中的项目总数,以下是代码:

const char* list_of_filename[] = {"One","Two","Three","Four","Five"};
4

2 回答 2

7

查找数组中元素个数的标准习语是

int num_items = sizeof(list_of_filename) / sizeof(list_of_filename[0]);
于 2012-04-05T01:53:57.903 回答
2

怎么样:

sizeof(list_of_filename) / sizeof(char*)

或更一般地说:

sizeof(list_of_filename) / sizeof(list_of_filename[0])
于 2012-04-05T01:54:09.597 回答