---
title: "数组名和数组名取地址区别"
author: "yqin"
date: "2009-11-16T22:01:46Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2009-11-16T22:01:46Z"
id: 518488
url: "https://yqin.iteye.com/blog/518488"
---

```
#include "stdio.h"
void main()
{
	int a[5]={1,2,3,4,5};
	int *ptr;
	ptr=(int *)(&a+1);
	printf("%d,%d",*a,*(ptr-1));
}
```

 

上面运行的结果为：1，5 为什么会是这个结果呢？ 这是因为数组名和数组名取地址之间是有区别的。

其实a和 &a结果都是数组的首地址，但他们的类型是不一样。其实a表示&a\[0],也即对数组首元素取地址，a+1表示首地址+sizeof(元素类型大小)。&a虽然值为数组首元素地址，但类型为：类型 (\*)\[数组大小],所以&a+1大小为：首地址+sizeof(a)