查找数组的大小,而不使用C中的sizeof [英] Find size of array without using sizeof in C
本文介绍了查找数组的大小,而不使用C中的sizeof的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种方式来找到C中的数组的大小,而无需使用的sizeof
C和我发现下面的code:
I was searching for a way to find the size of an array in C without using sizeof
in C and I found the following code:
int main ()
{
int arr[100];
printf ("%d\n", (&arr)[1] - arr);
return 0;
}
任何人都可以请解释我它是如何工作的?
Can anyone please to explain me how is it working?
推荐答案
&放大器;改编
是一个指向100数组 INT
秒。
&arr
is a pointer to an array of 100 int
s.
的 [1]
表示增加的是指向大小事,这是100的数组 INT
秒。
The [1]
means "add the size of the thing that is pointed to", which is an array of 100 int
s.
所以之间的差异(安培; ARR)[1]
和改编
100 INT
秒。
(请注意,这招只会在的sizeof
无论如何都会努力地工作。)
(Note that this trick will only work in places where sizeof
would have worked anyway.)
这篇关于查找数组的大小,而不使用C中的sizeof的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文