Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要帮助来计算存储在数组中的元素总数。例如,如果我有类似的东西,
int a[10] = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8};
如您所见,数组的元素小于数组的大小即10。那么如何计算数组中的元素总数?
这将返回数组的大小,即 10:
(int)( sizeof(a) / sizeof(a[0]));
C++ 编译器无法区分实际值和垃圾值。