else语句总是与离它最近的if语句配对,所以在if语句的嵌套中一定要注意else语句与哪个if语句匹配

#include <iostream>
using namespace std;
//if和else语句嵌套时候的易错点
int main()
{
    int x;
    cin << x;
    if(x > 1)
        if(x > 100) printf("x大于100\n");
        else printf("x大于1小于100\n");//注意这里易错, else属于嵌套的内部的if
}

 

相关文章:

  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2021-05-29
  • 2022-12-23
  • 2021-05-07
相关资源
相似解决方案