所有维度中包含1个元素的多维数组 [英] Multidimensional array with 1 element in all dimensions

查看:76
本文介绍了所有维度中包含1个元素的多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题可能看起来很有趣,但以下声明是否相同?


unsigned char a;

unsigned char b [1];

unsigned char c [1] [1] [1];


我的编译器为a存储一个字节,一个用于b,一个用于c。那么可以像第3行一样声明一个数组吗?或者这是一个捕获?例如,c [0] [0] [0]的处理速度会慢于?


谢谢。

解决方案

这三个定义是不同的,否则它们看起来是一样的。桌子不是牛,因为它们都有四条腿。因此,变量的大小是无关紧要的。


阅读: http://bytes.com/topic/c/insights/77...rrays-revealed


这是一篇非常好的文章,顺便祝贺。我很久以前就已经读过了,但它仍然没有包含我的问题的答案。我同意牛和桌子之间的比较,这就是我问的原因。由于它们都存储1个字节,有什么区别?


我在下面写了这段代码:

展开 | 选择 | Wrap | 行号


这样看:

展开 | 选择 | Wrap | 行号

The question may look funny, but are the following declarations equivalent?

unsigned char a;
unsigned char b[1];
unsigned char c[1][1][1];

My compiler stores one byte for a, one for b and one for c. So is it OK to declare an array like line 3 or is this a catch somewhere? For example will c[0][0][0] be processed slower than a?

Thanks.

解决方案

Thos three definitions are different otherwise they would look the same. A table is not a cow just because they both have four legs. Therefore, the size of the variable is irrelevant.

Read this: http://bytes.com/topic/c/insights/77...rrays-revealed


That''s a very good article, congratulations by the way. I have read it a long time ago but still it does not include an answer for my question. I agree about the comparison between cow and table, that''s why I asked. Since they all store 1 byte, what''s the difference?

I wrote this piece of code below:

Expand|Select|Wrap|Line Numbers


Look at it this way:

Expand|Select|Wrap|Line Numbers


这篇关于所有维度中包含1个元素的多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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