用C数组索引类型++ [英] Type of array index in C++

查看:93
本文介绍了用C数组索引类型++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是数组索引的C ++编程语言的类型?例如,在这样的语句:

What is the type of array index in C++ programming language? For example in such statement:

int tab[5];

要什么类型的5被转换?或者它只是普通int?

To what type 5 is converted? or maybe is it just plain int?

推荐答案

在code, 5 只是一个普通的整数文字,所以它只是一个普通的 INT 在这里。

In that code, 5 is just a plain integer literal, so it's just a plain int here.

§8.3.4的阵列的于n3290(〜C ++ 11)指定组声明:

§8.3.4 Arrays in n3290 (~ C++11) specifies array declarators:

在声明T d设定其中D具有形式

In a declaration T D where D has the form

D1 [ constant-expressionopt ] attribute-specifier-seqopt

和标识符在声明类型T D1是派生声明符类型列表T,那么D的标识符的类型是数组类型;如果D的识别符的类型包含自动类型说明符时,不良形成的程序。 T被称为数组元素类型;这种类型不得引用类型,(可能CV-合格)类型为void,函数类型或抽象类的类型。如果恒恩pression(5.19)是present,这应该是一个整型常量前pression其值应大于更大零

and the type of the identifier in the declaration T D1 is "derived-declarator-type-list T", then the type of the identifier of D is an array type; if the type of the identifier of D contains the auto type-specifier, the program is ill-formed. T is called the array element type; this type shall not be a reference type, the (possibly cv-qualified) type void, a function type or an abstract class type. If the constant-expression (5.19) is present,it shall be an integral constant expression and its value shall be greater than zero.

§5.2.1的下标的描述了可以在EX pressions括号去:

§5.2.1 Subscripting describes what can go in the brackets in expressions:

一个后缀前pression随后在方括号中前pression是一个后缀前pression。其中前pressions应具有类型指针T和其他应有的无作用域枚举或整型
  其结果是类型T的左值类型为T应是一个完全定义的对象类型。这位前pression
  E1 [E2]是相同的(根据定义)至*((E1)+(E2))

A postfix expression followed by an expression in square brackets is a postfix expression. One of the expressions shall have the type "pointer to T" and the other shall have unscoped enumeration or integral type. The result is an lvalue of type "T." The type "T" shall be a completely-defined object type. The expression E1[E2] is identical (by definition) to *((E1)+(E2))

这篇关于用C数组索引类型++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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