什么是指针到数组的地步? [英] What is the point of pointers to arrays?

查看:113
本文介绍了什么是指针到数组的地步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我阅读有关指针,并在指向数组的指针的概念来了。事情是,一个指向数组的指针并没有真正有用的似乎在所有的,而不是使用指针,因为有一个偏移量来访问数组的元素,我可以直接拿到的元素。不过,我觉得如果我失去了为什么这些可能是有用的原因。

So, I was reading about pointers, and came across the concept of pointers to arrays. The thing is that a pointer to an array doesn't really seem useful at all, since instead of using a pointer to have an offset to access an array element, I could just get the element directly. However I feel as if I'm missing the reason why these can be useful.

因此​​,简而言之,什么是指向数组的指针点;如何以及为什么他们使用,并且他们有任何实际的应用?

So, in short, What is the point of pointers to arrays; How and why should they be used, and do they have any practical applications?

编辑:我在正常/简单数组,如上下文的意思是:

I meant this in the context of normal/simple arrays such as:

int array[5];

编辑:基思指出的那样,我专门问指向数组的指针,例如字符(* PTR)[42] 这是一个指向字符的42个元素的数组。

As Keith Pointed out, I'm specifically asking about pointers to arrays, for example char (*ptr)[42] which is a pointer to a 42-element array of char.

推荐答案

不幸的是一些答案您收到秀一下用C指针和数组misbeliefs,简言之:

Unfortunately some answers you received show misbeliefs about pointers and arrays in C, in brief:

1)的指针数组是不一样的指针的第一个元素

1) Pointer to array is not the same as pointer to first element.

2)声明数组类型是不一样的声明指针

2) Declaring array type is not the same as declaring pointer.

您可以发现用C常见问题解答部分充分说明相关指针与数组之间共同的困惑:的http:// C-FAQ .COM / aryptr / index.html的

You can found full description in C faq part related to common confusion between pointers and arrays: http://c-faq.com/aryptr/index.html

Adressing你的问题 - 指针数组是有用的参数传递期间通过的关于它的大小编译时已知大小和preserve信息的整个阵列。多二维数组打交道时,你该怎么上的一些阵列的子数组操作时,也有用。

Adressing your question - pointer to array is usefull to pass an entire array of compile-time known size and preserve information about its size during argument passing. It is also usefull when dealing with multi dimensional arrays when you what to operate on subarray of some array.

这篇关于什么是指针到数组的地步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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