你知道吗? [英] Did you know?

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

问题描述

您是否知道以下if语句在语义上是正确的,但在逻辑上可能是错误的?


if(i = 2)

{

/ *做点什么* /

}


提示:

编译器可能只生成一个waring:可能不正确

赋值,但我们可能会忽略它。为了避免这样的错误,

只需反转这两个标识符。


if(2 == i)

{

/ *做点什么* /

}


如果''==''被''=''取代,编译器会给出一个错误

说Lvalue required。


-

"当你满意的时候和霍姆斯先生一起用餐?哈德森太太,好奇地问了房东太太。

七点半,后天。他说他参与了他的工作。

Did you know that the following if statement is semantically
right, but could logically be wrong?

if ( i = 2 )
{
/* do something */
}

Tip:

The compiler may only produce a waring: "Possibly incorrect
assignment", but we may ignore it. To avoid such a mistake,
just reverse the two identifiers.

if ( 2 == i )
{
/* do something */
}

If ''=='' is replaced by an ''='', the compiler will give an error
saying "Lvalue required".

--
"When you will be pleased to dine, Mr. Homles?" asked Mrs Hudson,
the landlady, curiosly.
"At seven thirty, the day after tomorrow." said he invovled in his work.

推荐答案

Vijay Kumar R Zanvar< vi ***** @ hotmail.com>潦草地写道:
Vijay Kumar R Zanvar <vi*****@hotmail.com> scribbled the following:
你知道以下if语句在语义上是对的吗,但逻辑上可能是错的?
如果(i = 2)
{
/ *做某事* /
}
提示:
编译器可能只产生一个waring:"可能不正确
分配,但我们可能会忽略它。为了避免这样的错误,
只需反转两个标识符。
if(2 == i)
{
/ *做点什么* /
}
如果''==''被''='取代',编译器会给出错误
说Lvalue required。
Did you know that the following if statement is semantically
right, but could logically be wrong? if ( i = 2 )
{
/* do something */
} Tip: The compiler may only produce a waring: "Possibly incorrect
assignment", but we may ignore it. To avoid such a mistake,
just reverse the two identifiers. if ( 2 == i )
{
/* do something */
} If ''=='' is replaced by an ''='', the compiler will give an error
saying "Lvalue required".




是的,我们确实知道这一切。但是谢谢你让我们知道。


-

/ - Joona Palaste(pa*****@cc.helsinki.fi) - -------------------------- \

| 飞翔的柠檬树中的金鸡王G ++ FR FW + M-#108 D + ADA N +++ |

| http://www.helsinki.fi/~palaste W ++ B OP + |

\ -----------------------------------------芬兰的规则! ------------ /

我正在寻找自己。你有没见过我?

- Anon



Yes, we did know all this. But thanks for letting us know anyway.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"I am looking for myself. Have you seen me somewhere?"
- Anon




" Joona I Palaste" < PA ***** @ cc.helsinki.fi>在消息中写道

news:bl ********** @ oravannahka.helsinki.fi ...

"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bl**********@oravannahka.helsinki.fi...
Vijay Kumar R Zanvar< vi ** ***@hotmail.com>潦草地写道:
Vijay Kumar R Zanvar <vi*****@hotmail.com> scribbled the following:




^^^^^^^^


我涂鸦了吗?



^^^^^^^^

Did I scribble?

您是否知道以下if语句在语义上是正确的,但逻辑上可能是错误的?


[...]

如果''==''被''=''替换,编译器会给出错误
说Lvalue required。
Did you know that the following if statement is semantically
right, but could logically be wrong?
[...]
If ''=='' is replaced by an ''='', the compiler will give an error
saying "Lvalue required".



是的,我们确实知道这一切。但是感谢你们让我们知道。

-
/ - Joona Palaste(pa*****@cc.helsinki.fi)--------- ------------------ \



Yes, we did know all this. But thanks for letting us know anyway.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\




我认为和你一起工作很有意思,Palaste先生。你必须是一个

的喜剧演员!!


-

我们接近了这个案子,你还记得Watson,他说:我有一个绝对空白的头脑,这绝对是一个优势。



I suppose it would be fun working with you, Mr. Palaste. You must be a
comedian!!

--
"We approached the case, you remember Watson," said
Mr. Homles, "with an absolutely blank mind, which is
always an advantage."

< br>

在文章< bl ************ @ ID-203837.news.uni-berlin.de>中,Vijay Kumar R Zanvar写道:
In article <bl************@ID-203837.news.uni-berlin.de>, Vijay Kumar R Zanvar wrote:
您是否知道以下if语句在语义上是正确的,但在逻辑上可能是错的?

如果(i = 2)
{
/ *做某事* /
}
Did you know that the following if statement is semantically
right, but could logically be wrong?

if ( i = 2 )
{
/* do something */
}



是的,这是一个众所周知的事实,它在常见问题解答中:

http://www.eskimo.com/~scs/C-faq /q17.4.html

-

Andreas K?h?ri


Yes, it''s a well known fact and it''s in the FAQ:

http://www.eskimo.com/~scs/C-faq/q17.4.html
--
Andreas K?h?ri


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

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