挂别的问题? [英] Hanging else problem?

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

问题描述

什么是挂其他"问题?(这是正确的名字吗?)

What is the "hanging else" problem? (Is that the right name?)

遵循 C++ 编码标准(忘记哪个)我总是将括号(块)与控制结构一起使用.所以我不通常有这个问题(最后一个(?)其他属于),但为了理解可能存在的问题外国代码,如果能深入了解就会很好这个问题.我记得在一本关于帕斯卡很多年前,但我找不到那本书.

Following a C++ coding standard (forgot which one) I always use brackets (block) with control structures. So I don't normally have this problem (to which "if" does the last(?) else belong), but for understanding possible problems in foreign code it would be nice with a firm understanding of this problem. I remember reading about it in a book about Pascal many years ago, but I can't find that book.

推荐答案

else属于哪个if?

if (a < b)
    if (c < d)
        a = b + d;
    else
        b = a + c;

(显然你应该忽略缩进.)

(Obviously you should ignore the indentation.)

这就是其他问题".

C/C++ 通过规定不能将 an-if-without-an-else 作为 来消除歧义if-an-if-with-an-else 的主体.

C/C++ gets rid of the ambiguity by having a rule that says you can't have an-if-without-an-else as the if-body of an-if-with-an-else.

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

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