ç的sizeof的char *数组 [英] C sizeof char* array

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

问题描述

我有一个的char * 排列如下:

 的char * TBL [] = {1,2,3};

我如何使用的sizeof 运算符来获取数组元素的数量,在这里3?

下面做工作,但它是正确的?

  INT N = sizeof的(TBL)/ sizeof的(TBL [0])


解决方案

是,

 为size_t N = sizeof的(TBL)/ sizeof的(TBL [0])

是这样做的最典型方式。

请注意,使用 INT 数组的大小是不是最好的主意。

I have a char* array as follows:

char *tbl[] = { "1", "2", "3" };

How do I use the sizeof operator to get the number of elements of the array, here 3?

The below did work, but is it correct?

int n = sizeof(tbl) / sizeof(tbl[0])

解决方案

Yes,

size_t n = sizeof(tbl) / sizeof(tbl[0])

is the most typical way to do this.

Please note that using int for array sizes is not the best idea.

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

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