该指南的“并且由于数组实际上是指针”是什么意思? [英] What does this guide mean by "And since arrays are actually pointers"?

查看:88
本文介绍了该指南的“并且由于数组实际上是指针”是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习C,并且目前在指针部分: http://www.learn-c.org/zh-CN/Pointers

I'm in the process of learning C, and I'm currently on the pointer section: http://www.learn-c.org/en/Pointers

在指南中的某个地方它说:

At one point in the guide it says:


由于数组实际上是指针...

And since arrays are actually pointers...

数组是如何实际上是指针?我知道是否创建 char数组[20] array 是数组第一个元素的内存地址, (是指向该值,还是仅保留该值),对吗?

How are arrays actually pointers? I know if I create char array[20], array is the memory address of the first element of the array, (does it "point" to that, or just hold the value), right? Is that what they mean?

据我了解,数组只是一个内存地址序列,下标访问 [0] [1] 等只是这些内存地址上的值。我完全不满意吗?

As I understand it an array is just a sequence of memory addresses, and the subscript access [0], [1], etc. are just the values at those memory addresses. Am I totally off?

推荐答案

您不必相信在互联网上找到的所有内容:数组是不是指针。在某些情况下,对数组和指针的处理方式相同,但是在大多数情况下,数组是数组,而不是指针。

You don't have to trust everything that you find on the internet: arrays are not pointers. There are contexts in which arrays and pointers are treated in the same way, but for the most part arrays are, well, arrays, not pointers.

最重要的方面是使数组与指针不同的是

The most important aspects that make arrays differ from pointers are that


  • 数组有特定的数据区域;指针在使用前需要与存储区关联。

  • 不能重新分配数组以引用内存中的其他位置

  • 数组具有一个可以通过 sizeof
  • 检索的特定大小
  • 如果数组成员包含在 struct

  • Arrays have a specific area for their data; pointers need to be associated with a storage area before use
  • Arrays cannot be re-assigned to refer to a different place in memory
  • Arrays have a specific size that can be retrieved through sizeof
  • Array data will be copied if an array member is included in a struct

一种将数组和指针表现为相同的上下文是将它们传递给函数时:在这种情况下,编译器获取数组的地址,从中获取一个指针,然后将该指针传递给函数。该过程有时称为衰减到指针的数组。

One context in which arrays and pointers behave the same is when you pass them to a function: in this situation the compiler takes the address of the array, makes a pointer from it, and passes that pointer to a function. The process is sometimes referred to as "arrays decaying to a pointer".

这篇关于该指南的“并且由于数组实际上是指针”是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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