运营商[]

扫码查看
本文介绍了运营商[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到最近我掌握了指针和数组之间的关系和

我终于明白[]是一个运算符。但是我还是不能确定这一点:在一个声明中真正做到了[]:


int array [5];

int matrix [5] [5];

dArray = new int [];

dMatrix = new int * [];


此外,这是否有效(有用?):


int x;

int * array =& x ;

for(int i = 0; i< some_number; ++ i)

array [i] = //一些东西

Until recently I grasp the relationship between pointers and arrays and
I have finally understand that [ ] is an operator. But I still can''t
quite figure it out: What does really does [ ] in a statement such as:

int array[5];
int matrix[5][5];
dArray = new int[];
dMatrix = new int*[];

Also, is this valid (useful?):

int x;
int *array=&x;
for(int i=0; i<some_number; ++i)
array[i] = //some stuff

推荐答案




不,它对于除'0'以外的''i'的值无效(它有未定义的

行为),因此在正常编程中没用。


V



No, it''s not valid for values of ''i'' other than 0 (it has undefined
behaviour), and therefore not useful in normal programming.

V





我很少迷路!


当我使用类似的东西时:


int array [5];


我说'寻找5块空闲内存来分配int'和

创建一个指针数组到第一个街区是真还是假?


所以,当我说'


int matrix [5] [5];


它看起来是25块而不是5块,但是我不明白[5] [5]

的确意味着什么?


如果这就是它的工作方式那么它意味着什么:


那么


int array [5]




相同
int * array = new int [5]






I''m a little lost!

When I use something like:

int array[5];

I''m saying "look for 5 block of free memory to allocate int''s and
create a pointer "array" to the first block". True or false?

So when I''m saying

int matrix[5][5];

It looks for 25 blocks instead of 5, but I cn''t understand what [5][5]
really means?

And if that''s the way it works then what it means:

Then

int array[5]

is the same as

int* array = new int[5]

?





我很少迷路!


当我使用类似的东西时:


int array [5];


我说'寻找5块空闲内存来分配int'和

创建一个指针数组到第一个街区是真还是假?


所以,当我说'


int matrix [5] [5];


它看起来是25块而不是5块,但是我不明白[5] [5]

的确意味着什么?


如果这就是它的工作方式那么


int array [5]



相同

int * array = new int [5]






I''m a little lost!

When I use something like:

int array[5];

I''m saying "look for 5 block of free memory to allocate int''s and
create a pointer "array" to the first block". True or false?

So when I''m saying

int matrix[5][5];

It looks for 25 blocks instead of 5, but I cn''t understand what [5][5]
really means?

And if that''s the way it works then

int array[5]

is the same as

int* array = new int[5]

?


这篇关于运营商[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 15:43
查看更多