的C指针:数组变量 [英] C pointer : array variable

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

问题描述

我读到这在我的书(和互联网上的许多源):

I read this in my book (and many sources on the internet):

数组变量的以数组中的第一个元素。

The array variable points to the first element in the array.

如果这是真的,那么数组变量和第一个元素都是不同的。对吧?

If this true, then the array variable and the first element are different. Right?

这是指低于code,就会产生两种不同的结果:

It means by below code, it will produce two different results:

int main(){
    char msg[] = "stack over flow";
    printf("the store string is store at :%p\n",&msg);
    printf("First element: %p\n",&msg[0]);
}

不过,我收到两种情况相同的结果。因此,通过这个例子,我想我们应该说:数组变量的的第一个元素。 (因为它具有相同的地址)

But I receive the same results for the two cases. So, by this example, I think we should say: the array variable is the first element. (because it has the same address)

我不知道这是真的还是错。请教我。

I don't know if this true or wrong. Please teach me.

推荐答案

数组变量表示整个存储器块阵列占据,不仅该数组的第一个元素。因此,阵列不可以一样数组[0] (见的sizeof阵列/ sizeof的数组[0] )。但该阵列的第一个元件位于同一存储器地址作为数组本身

The array variable signifies the entire memory block the array occupies, not only the array's first element. So array is not the same as array[0] (cf. sizeof array / sizeof array[0]). But the array's first element is located at the same memory address as the array itself.

话说阵列指向第一元件也是不正确的,在大多数情况下,一个阵列的前pression衰变成指向其第一元件,但它们是不同的事情(再次参见 sizeof的为例)。

Saying the array points to the first element is also incorrect, in most circumstances, an array expression decays into a pointer to its first element, but they are different things (again cf. sizeof for example).

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

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