我怎样才能得到一个数组的C / Objective-C的大小? [英] How can I get the size of an array in C / Objective-C?

查看:68
本文介绍了我怎样才能得到一个数组的C / Objective-C的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数组:

unsigned char* data = CGBitmapContextGetData(cgctx);

然后我试图让与的sizeof(数据)的大小,但4数据保存的信息数量较大,将返回我无义值。这不能只是4;)

then I tried to get the size with sizeof(data), but that will return me a nonsense-value of 4. data holds a big amount of information. That can't be just 4 ;)

我甚至都得到在数据[8293]信息...所以...不是4个元素。

I even get information at data[8293] ... so ... not 4 elements at all.

推荐答案

的sizeof 返回4,因为您的变量声明为一个指针,而不是C数组( char数据[1024] )。

sizeof returns 4 because your variable is declared as a pointer, as opposed to a C array (char data[1024]).

要得到你需要使用大小 CGBitmapContextGetHeight CGBitmapContextGetWidth

To get the size you need to use CGBitmapContextGetHeight and CGBitmapContextGetWidth.

这篇关于我怎样才能得到一个数组的C / Objective-C的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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