分类: C/C++
2008-05-13 14:35:45
|
(
以下摘自ypxing博客中的《数组与指针--都是“退化”惹的祸》
http://blog.chinaunix.net/u1/35100/showart_445864.html
)
C99中原话:
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.上面这句话说的很清楚了, 数组在除了3种情况外, 其他时候都要"退化"成指向首元素的指针.
比如对 char s[10] = "china";
这3中例外情况是:
(1) sizeof(s)
(2) &s;
(3) 用来初始化s的"china";
除了上述3种情况外,s都会退化成&s[0], 这就是数组变量的操作方式
因此数组名作函数参数时,char a[]退化成char *a,char *b[] 退化成 char **b,char c[n][m]退化成 char (*c)[m]