bool真的总是== 1吗? [英] Does bool true always == 1?

查看:90
本文介绍了bool真的总是== 1吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准c ++是否定义true?总是等于1?


我的代码:

int num = 1 +(value1 == value2);


我可以确定num总是1或2?如何在Windows机器上获得


Does standard c++ define "true" to be always equal to 1?

My code:
int num = 1 + (value1== value2);

Can I be certain that "num" will ALWAYS be either 1 or 2? How about
on a Windows machine?

推荐答案

Nollie写道:

标准c ++是否定义了true总是等于1?


是。

当bool值转换为整数值时,则

false - > 0

true - > 1

我的代码:
int num = 1 +(value1 == value2);

我可以肯定num总是1或2?在Windows机器上怎么样?

Does standard c++ define "true" to be always equal to 1?
Yes.
When a bool value is converted to an integer value, then
false -> 0
true -> 1

My code:
int num = 1 + (value1== value2);

Can I be certain that "num" will ALWAYS be either 1 or 2? How about
on a Windows machine?




这不是Windows的问题,也不是Windows的问题。

这是一个问题ofC ++ - The language。


-

Karl Heinz Buchegger
kb ****** @ gascad.at


* Nollie:
standard c ++ definetrue总是等于1?


总是转换为1,是的。


我的代码:
int num = 1 +(value1 = = value2);

我可以确定num总是1或2?


适用于内置类型。


通常不会,因为程序员可以定义含义

''==''。

在Windows机器上怎么样?
Does standard c++ define "true" to be always equal to 1?
In the sense of always converting to 1, yes.

My code:
int num = 1 + (value1== value2);

Can I be certain that "num" will ALWAYS be either 1 or 2?
Yes for built-in types.

No in general, because it''s possible for the programmer to define the meaning
of ''==''.

How about on a Windows machine?




不相关。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么是这是一件坏事吗?

答:热门发布。

问:usenet和电子邮件中最烦人的是什么?



Irrelevant.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?




" Nollie" <铝********* @ Auburn.com> schrieb im Newsbeitrag

新闻:p2 ******************************** @ 4ax.com ...

"Nollie" <Al*********@Auburn.com> schrieb im Newsbeitrag
news:p2********************************@4ax.com...
标准c ++是否定义true?总是等于1?

我的代码:
int num = 1 +(value1 == value2);

我可以确定num ;总是1或2?在Windows机器上怎么样?
Does standard c++ define "true" to be always equal to 1?

My code:
int num = 1 + (value1== value2);

Can I be certain that "num" will ALWAYS be either 1 or 2? How about
on a Windows machine?




从关于整体提示的标准引用(4.5)


" ; bool类型的rvalue可以转换为int类型的rvalue,

false变为零,true变为1。


干杯


克里斯



Quoting from the standard about integral prompotions (4.5)

"An rvalue of type bool can be converted to an rvalue of type int, with
false becoming zero and true becoming one."

Cheers

Chris


这篇关于bool真的总是== 1吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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