有没有在C数组的大小/长度的捷径? [英] Is there any shortcut for array size / length in C?
本文介绍了有没有在C数组的大小/长度的捷径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么办法,以加快用C得到一个数组的大小?
Is there any way to speed up getting an array size in C?
键入了的sizeof(阵列)/的sizeof(INT)
每次变老。是否有任何C库有类似。长度
或者是有一些方法可以让我定义的sizeof(阵列)/的sizeof(INT)
为某种更短的常量(也可以用点表示)?
Typing out sizeof(array)/sizeof(int)
every time gets old. Do any C libraries have something like .length
or is there some way I can define sizeof(array)/sizeof(int)
as a shorter constant of some sort (possible also using dot notation)?
推荐答案
您可以使用的sizeof(阵列)/的sizeof(*数组)
并作出宏。
#define length(array) (sizeof(array)/sizeof(*(array)))
这篇关于有没有在C数组的大小/长度的捷径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文