这将是如果第一个被定义为1枚举元素的值? [英] What will be the value of enum element if the first one is defined to 1?

查看:302
本文介绍了这将是如果第一个被定义为1枚举元素的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

enum e {
    X=1,
    Y,
    Z
}

会有什么如果第一个被定义为1枚举元素的值?

What will be the values of enum elements if the first one is defined to 1?

将其他元素被各1个加一?

Will the other elements be incremented by 1 each one?

推荐答案

由于大家都在说,答案是肯定的。这里说的标准的方法。

As everyone else is saying, the answer is yes. Here's the standard's way of saying that.

C99规格。第6.7.2.2枚举符。第3

在枚举列表中的标识符被声明为具有类型int和可能出现这样是允许的地方常数。)与=枚举器定义了它的枚举常量的常量前pression的价值。如果第一枚举没有=,其枚举常量的值是0

The identifiers in an enumerator list are declared as constants that have type int and may appear wherever such are permitted.) An enumerator with = defines its enumeration constant as the value of the constant expression. If the first enumerator has no =, the value of its enumeration constant is 0.

每个后续枚举没有=定义其枚举常数通过加入1至previous枚举恒定的值而获得的恒定的恩pression的值。 (统计员与=的使用会产生枚举常量与重复在同一枚举其他值的值。)

Each subsequent enumerator with no = defines its enumeration constant as the value of the constant expression obtained by adding 1 to the value of the previous enumeration constant. (The use of enumerators with = may produce enumeration constants with values that duplicate other values in the same enumeration.)

枚举的统计员也被称为它的成员。

The enumerators of an enumeration are also known as its members.

这篇关于这将是如果第一个被定义为1枚举元素的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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