如何找到物品的长度/数present一个数组? [英] How do I find the length/number of items present for an array?

查看:104
本文介绍了如何找到物品的长度/数present一个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  在功能参数数组的长度

我的数组大小为5。例如:

My array size is 5. For example:

arrCustId[5]

我怎么能知道有多少客户ID已经被present在我的阵列?
总之如何找到数组长度?

How can I know how many Customer IDs are already present in my array? In short how to find length of array?

推荐答案

如果数组是静态分配,使用的sizeof(阵列)/的sizeof(数组[0])

If the array is statically allocated, use sizeof(array) / sizeof(array[0])

如果它是动态分配的,但是,不幸的是你的运气,因为这一招总是返回的sizeof(POINTER_TYPE)/ sizeof的(数组[0])(其中将有4个32位系统用char * S上),你可以或者a)保持的#define(或常量)不变,但或b)保持变量。

If it's dynamically allocated, though, unfortunately you're out of luck as this trick will always return sizeof(pointer_type)/sizeof(array[0]) (which will be 4 on a 32 bit system with char*s) You could either a) keep a #define (or const) constant, or b) keep a variable, however.

这篇关于如何找到物品的长度/数present一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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