阵列基指针和它的地址相同。为什么? [英] Array base pointer and its address are same. Why?

查看:139
本文介绍了阵列基指针和它的地址相同。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的程序。

#include <stdio.h>

int main()
{
  int a[10]={0};

  printf("%p %p\n", a, &a);
  printf("%d %d\n", *a, *(&a));

  return 0;
}

a和安培&;一个是相同的。但是* a和*(&放大器;一个)不是。我出答案。请帮助。

a and &a are same. But *a and *(&a) are not. I am out of answers. Please help.

推荐答案

有没有阵列基本指针,即有没有指向数组的指针变量。数组的名称是指的阵列本身的。因此,你不能拿的 A ,相反,&放一个地址;一个作为一种特殊情况的处理

There is no "array base pointer", i.e. there no pointer variable that points to the array. The name of the array refers to the array itself. Therefore you can not take an address of a, instead, &a is handled as a special case.

当您在一个前pression使用数组的名字,它的衰减的成指向数组的第一个元素的指针。然而,&放大器; 的sizeof 运营商的例外

When you use the name of an array in an expression, it decays into a pointer that points to the first element of the array. However, & and sizeof operators are exceptions.

ANSI C指定&安培; A 表示数组本身的地址,其类型为指针数组,而不是指针数组元素

ANSI C specifies that &a means the address of the array itself, and its type is "pointer to array", not "pointer to array element".

在pre-ANSI编译器,放大器和;一个会产生警告

In pre-ANSI compilers, &a would cause a warning.

这篇关于阵列基指针和它的地址相同。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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