关于“enums”的问题 [英] Question about "enums"

查看:79
本文介绍了关于“enums”的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在K& R练习的其中一个练习中,前几行是:


enum loop {NO,YES};

枚举循环okloop = YES;


我得到第一行,但不是第二行。


对LOL问题抱歉。


提前致谢

In one of the answers to a K&R exercise, the first couple of lines are:

enum loop { NO, YES};
enum loop okloop=YES;

I get the first line, but not the second.

Sorry about the LOL question.

Thanks in advance

推荐答案

mdh写道:
在一个对于K& R练习的答案,前几行是:

枚举循环{NO,YES};
枚举循环okloop = YES;
In one of the answers to a K&R exercise, the first couple of lines are:

enum loop { NO, YES};
enum loop okloop=YES;



oklopp我们是enum类型循环的一个变量,所以你可以为它指定NO

或YES。


-

Ian Collins。


oklopp us a variable of the enum type loop, so you can assign either NO
or YES to it.

--
Ian Collins.




Ian Collins写道:


Ian Collins wrote:

oklopp我们是enum类型循环的一个变量,所以你可以给它分配NO
或YES。
oklopp us a variable of the enum type loop, so you can assign either NO
or YES to it.




它必须迟到或者过多C :-)


我猜ss我所缺少的是:


枚举循环{YES,NO}


那么呢?

我认为这背后的想法是给

分配一个整数是,不是吗? (在这种情况下,0和1?)


那么为什么不简单地使用术语是?和否?


提前谢谢?



It must be late or too much C :-)

I guess what I am missing is what the:

enum loop { YES,NO}

then does?

I thought that the idea behind this was to assign an integer to the
YES, NO? ( In this case 0 and 1?)

Then why not simply use the terms "YES" and "NO"?

Thanks in advance?


mdh写道:
Ian Collins写道:
Ian Collins wrote:
oklopp us一个enum类型循环的变量,所以你可以给它分配NO
或YES。
一定是迟到还是太多C :-)

我想我错过的是:

枚举循环{YES,NO}
<那么呢?
oklopp us a variable of the enum type loop, so you can assign either NO
or YES to it.

It must be late or too much C :-)

I guess what I am missing is what the:

enum loop { YES,NO}

then does?



枚举是一种类型,在这种情况下可以有两个值之一,YES

和NO。


未定义任何其他值到循环。不幸的是C

编译器不认为这是一个错误,这使得枚举比符号常量更多



我认为这背后的想法是给
分配一个整数,是吗? (在这种情况下0和1?)

那么为什么不简单地使用术语是?和否?


An enum is a type, which in this case can have one of two values, YES
and NO.

Assigning any other value to a loop is undefined. Unfortunately C
compilers don''t regard this as an error, which renders enums little more
than symbolic constants.
I thought that the idea behind this was to assign an integer to the
YES, NO? ( In this case 0 and 1?)

Then why not simply use the terms "YES" and "NO"?



你可以,


int n = YES;


完全没问题。


-

Ian Collins。


you can,

int n = YES;

Is perfectly OK.

--
Ian Collins.


这篇关于关于“enums”的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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