ç发现静态数组的大小 [英] C find static array size

查看:155
本文介绍了ç发现静态数组的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 静态的char * theFruit [] = {
    柠檬,
    橙子,
    苹果,
    香蕉
};

我知道大小为4通过看这个数组。如何以编程方式找到这个阵中C的大小?我不想以字节为单位的大小。


解决方案

 的sizeof(theFruit)/ sizeof的(theFruit [0])

注意的sizeof(theFruit [0])==的sizeof(字符*),恒定的。

static char* theFruit[] = {
    "lemon",
    "orange",
    "apple",
    "banana"
};

I know the size is 4 by looking at this array. How do I programmatically find the size of this array in C? I do not want the size in bytes.

解决方案

sizeof(theFruit) / sizeof(theFruit[0])

Note that sizeof(theFruit[0]) == sizeof(char *), a constant.

这篇关于ç发现静态数组的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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