Welcome to My Public Vault

Home

❯

dangling else

dangling else

Apr 15, 20261 min read

  • CPlusPlus

入れ子になったif文(C++)で、elseがどのifに対応するかが読み手にとって曖昧になりやすい問題。 構文上は、elseはもっとも近いifに結び付く。

if (a <= 10)
    if (a <= 5)
        std::cout << a << "<=5\n";
else
    std::cout << a << "> 5\n";

関連

  • if文(C++)

参考

  • https://www.learncpp.com/cpp-tutorial/common-if-statement-problems/

Graph View

  • 関連
  • 参考

Backlinks

  • C++(Roadmap)

Created with Quartz v4.5.2 © 2026

  • GitHub
  • Discord Community