当数组变量被认为是指针,当它被认为是简单的数组? [英] When the array variable is considered as pointer and when it is considered as simple array?

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

问题描述

当数组变量被认为是指针,当它被认为是在C简单阵列?如上例有时的sizeof(array_variable)运算符返回地址的大小,有时它返回数组的大小。

When the array variable is considered as pointer and when it is considered as simple array in C? As example sometimes sizeof(array_variable) operator returns the address size and sometimes it returns the size of the array.

推荐答案

Ç2011(N1570)6.3.2.1 3:

C 2011 (N1570) 6.3.2.1 3:

除非它是在的sizeof 运算符的操作数,在 _Alignof运营商或一元的&安培; 运营商,或者是一个字符串文字用于初始化数组,即具有类型''转换为类型的前pression''指针的键入中的键入的阵'的前$​​ p $ pssion 的''指向数组对象的初始元素,不是左值。如果数组对象有注册存储类,这种行为是未定义。

Except when it is the operand of the sizeof operator, the _Alignof 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.

Ç2011(N1570)6.7.6.3 7:

C 2011 (N1570) 6.7.6.3 7:

一个参数的声明为''的数组的键入的''应调整到'合格指针的键入的'',其中类型修饰符(如果有的话)正在内的那些指定在 [] 数组类型派生的。

A declaration of a parameter as ‘‘array of type’’ shall be adjusted to ‘‘qualified pointer to type’’, where the type qualifiers (if any) are those specified within the [ and ] of the array type derivation.

这篇关于当数组变量被认为是指针,当它被认为是简单的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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