int x=1,y=0; if(!x)y++; else if(x==0) if(x)y+=2; else y+=3;这段程序是什么意思

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/10 03:23:13
int x=1,y=0; if(!x)y++; else if(x==0) if(x)y+=2; else y+=3;这段程序是什么意思

int x=1,y=0; if(!x)y++; else if(x==0) if(x)y+=2; else y+=3;这段程序是什么意思
int x=1,y=0; if(!x)y++; else if(x==0) if(x)y+=2; else y+=3;
这段程序是什么意思

int x=1,y=0; if(!x)y++; else if(x==0) if(x)y+=2; else y+=3;这段程序是什么意思
在java中这个if(!x)应该是错了吧,整型变量好像不能做判断.
不过在C和C++中可以,在if(!x)这句判断时为假,所以y++并不执行.
然后进行if(x==0)判断,因为x=1值并没有发生改变,
而if(x)y+=2; else y+=3;都是包括在if(x==0)的判断条件里的,
所以之后的if(x)y+=2; else y+=3;都不执行.
最后的x,y的值仍然是x=1,y=0