算在C中的数组元素的数 [英] Count the number of elements in an array in C

查看:141
本文介绍了算在C中的数组元素的数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能获得在C中的整数数组元素present数的数组传递给函数的后面?下面code不起作用。

 尺寸= sizeof的(阵列)/的sizeof(数组[0]);


解决方案

在C,你只能得到静态分配数组的大小,即

  int数组[10];
大小= sizeof的(阵列)/的sizeof(int);在

将给予10。

如果您的数组声明或为int *阵列过去了,没有办法确定其大小,只给出这个指针。

How can I obtain the number of elements present in an integer array in C after the array is passed to a function? The following code doesn't work.

size=sizeof(array)/sizeof(array[0]);

解决方案

In C, you can only get the size of statically allocated arrays, i.e.

int array[10];
size = sizeof(array) / sizeof(int);

would give 10.

If your array is declared or passed as int* array, there is no way to determine its size, given this pointer only.

这篇关于算在C中的数组元素的数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆