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 "); else printf("x大于1小于100 ");//注意这里易错, else属于嵌套的内部的if }
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 "); else printf("x大于1小于100 ");//注意这里易错, else属于嵌套的内部的if }