如何确定C中的数组elemnts多少? [英] How to determine the number of array elemnts in C?

查看:121
本文介绍了如何确定C中的数组elemnts多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C(我用gcc 4.8.0)的函数接收一个数组作为它的参数。有没有办法准确地确定数组中元素的个数,不传递一个额外的参数array_count?

I have a function in C (I am using gcc 4.8.0) which receives an array as its argument. Is there a way to accurately determine the number of elements in the array, without passing an additional argument array_count?

推荐答案

阵列衰变到函数参数指针所以无法确定大小。

Arrays decay into pointers in function arguments so size cannot be determined.

这是左值[见问题2.5 ]型数组的-T出现在一个前pression衰变(有三个例外)到一个指向它的第一要素;所得指针的类型是指针到-T,因为阵列是不是一个修改的左值,

An lvalue [see question 2.5] of type array-of-T which appears in an expression decays (with three exceptions) into a pointer to its first element; the type of the resultant pointer is pointer-to-T because an array is not a "modifiable lvalue,"

(例外情况是,当阵列是sizeof的或放大器的操作数;操作者,或为字符阵列的文字串初始化)

(The exceptions are when the array is the operand of a sizeof or & operator, or is a literal string initializer for a character array.)

这篇关于如何确定C中的数组elemnts多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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