指向C中数组的指针 [英] Pointer to Array in C

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

问题描述

您如何解释以下代码行?

How can you interpret the following line of code?

int (*arrayABC)[10];

在我的教科书中,它说我们有一个指向整数数组第0个元素的指针.

In my textbook, it says that we have a pointer to a pointer to the 0th element of an integer array.

但是,我对此不太了解.

However, I don't quite understand this.

我的解释:我们有一些变量,它的值是某个地址.然后,该地址是UNNAMED整数数组的第0个元素的地址.基本上,我们有一个指向第0个元素的指针.

My interpretation: We have some variable, which gets as its value some address. This address is then the address of the 0th element of an UNNAMED integer array. Basically we have a pointer to the 0th element.

那为什么要有指向POINTER的指针呢?

Why then to have a pointer TO A POINTER?

推荐答案

这是指向数组的指针.它不是指向指针的指针.数组和指针是不同的.数组具有一个地址,但数组不是一个地址.数组是一系列连续的元素.

This is a pointer to an array. It is not a pointer to a pointer. Arrays and pointers are different. An array has an address, but an array is not an address. An array is a series of contiguous elements.

此指针不仅指向第一个元素,还指向整个数组,而 float * 指向整个浮点,而不仅仅是第一个字节.

This pointer points to the whole array and not just the first element, in the same way that a float * points to the whole float and not just the first byte.

例如,如果您有:

int foo[10];
int (*arrayABC)[10] = &foo;

然后,表达式(* arrayABC) foo 是相同的.例如. foo [3] (* arrayABC)[3] 相同.

then the expressions (*arrayABC) and foo are identical. E.g. foo[3] is the same as (*arrayABC)[3].

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

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