我有下面的代碼來選擇正弦或餘弦加以整合,C,而環路邏輯(Y!=(1 || 0))
while(x !=1 || y !=(1||0)){
printf("Sin (1) or Cos (0)?\n");
x = scanf("%d",&y);
_flushall();
if(y==1){
printf("Sin set\n");
}
else if(y==0){
printf("Cos set\n");
}
}
然而
y!= (1||0)
從未評估對於y == 0爲true,有人可以解釋這裏有什麼問題嗎?謝謝。
這一定是真實的,或者你能只能保證(0 || 1)ISN」 t 0(這仍然會給OP帶來相同的行爲)? – 2012-04-27 15:33:17
請參閱:http://stackoverflow.com/questions/7687403/is-the-true-result-of-or-defined/7687444#7687444 – Mat 2012-04-27 15:34:21
@ScottHunter:'||'和'&&'將評估爲1爲真,0表示錯誤。 – 2012-04-27 15:55:12