## 第一章 数组与指针概念剖析 转

北极心

“一维数组是一级指针”

“二维数组是二级指针”

“数组名是一个常量指针”

“数组名是一个指针常量”

........................

6.2.5 Types

A pointer type may be derived from a function type, an object type, or an incomplete type, called the referenced type. A pointer type describes an object whose value provides a reference to an entity of the referenced type. A pointer type derived from the referenced type T is sometimes called ‘‘pointer to T’’. The construction of a pointer type from a referenced type is called ‘‘pointer type derivation’’.

Semantics

The unary & operator returns the address of its operand. If the operand has type “type”, the result has type “pointer to type”....... Otherwise, the result is a pointer to the object or function designated by its operand.

3.9.2 Compound types

....... Except for pointers to static members, text referring to “pointers” does not apply to pointers to members..........

6.2.5 Types

An array type describes a contiguously allocated nonempty set of objects with a particular member object type, called the element type. Array types are characterized by their element type and by the number of elements in the array. An array type is said to be derived from its element type, and if its element type is T, the array type is sometimes called “array of T”. The construction of an array type from an element type is called “array type derivation”.

int a[10];

a的数组类型描述就是int[10]。

C89/90的内容：

6.2.2.1 Lvalues and function designators

Except when it is the operand of the sizeof operator or the unary & operator, or is a character string literal used to initialize an array of character type. or is a wide string literal used to initialize an array with element type compatible with wchar-t, an lvalue that has type “array of type” is converted to an expression that has type “pointer to type” that points to the initial element of the array object and is not an lvalue.

C99的内容：

6.3.2.1 Lvalues, arrays, and function designators

Except when it is the operand of the sizeof operator or the unary & operator, or is a string literal used to initialize an array, an expression that has type “array of type” is converted to an expression with type “pointer to type” that points to the initial element of the array object and is not an lvalue. If the array object has register storage class, the behavior is undefined.

C89/90规定：

an lvalue that has type “array of type” is......

an expression that has type “array of tye” is.......

C99中去掉了lvalue的词藻，为什么？我们知道，数组名是一个不可修改的左值，但实际上，也存在右值数组。在C中，一个左值是具有对象类型或非void不完整类型的表达式，C的左值表达式排除了函数和函数调用，而C++因为增加了引用类型，因此返回引用的函数调用也属于左值表达式，就是说，非引用返回的函数调用都是右值，如果函数非引用返回中包含数组，情况会怎样？考虑下面的代码：

``````#include <stdio.h>
struct Test
{
int a[10];
};
struct Test fun( struct Test* );

int main( void )
{
struct Test T;
int *p = fun( &T ).a;                   /* A */

int (*q)[10] = &fun( &T ).a;            /* B */

printf( "%d", sizeof( fun( &T ).a ) );  /* C*/
return 0;
}

struct Test fun( struct Test *T )
{
return *T;
}``````

An lvalue or rvalue of type “array of N T” or “array of unknown bound of T” can be converted to an rvalue of type “pointer to T.” The result is a pointer to the first element of the array.

### 北极心

so_foolish
2017/04/01
0
0

http://blog.csdn.net/cndes/art ... 88771 这有一篇文章，说是剖析beetl模板引擎，并与同为国内的tiny模板引擎做对比(以下简称“剖析beetl”)，其剖析过程公正，但结论却不正确（文中暗示的...

2016/07/14
0
9

2017/11/07
0
0
C/C++程序员应聘常见面试题深入剖析

C/C++程序员应聘常见面试题深入剖析 1.引言 　　本文的写作目的并不在于提供C/C++程序员求职面试指导，而旨在从技术上分析面试题的内涵。文中的大多数面试题来自各大论坛，部分试题解答也参考...

2012/12/14
0
0
Clang array of pointer and pointer of arrayC语言数...

wape-yang
2013/09/21
0
0

16分钟前
0
0
2. 红黑树

17分钟前
0
0
input的button类型，点击页面跳转

Sunki
23分钟前
0
0

dkvirus
28分钟前
0
0
zookeeper和HBASE总结

zookeeper快速上手 zookeeper的基本功能和应用场景 zookeeper的整体运行机制 zookeeper的数据存储机制 数据存储形式 zookeeper中对用户的数据采用kv形式存储 只是zk有点特别： key：是以路径...

51分钟前
1
0