[問題] 關於遞增符號和bitwise問題
*[36m開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
linux
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
無
問題(Question):
bitwise與遞增符號結合
餵入的資料(Input):
無
預期的正確結果(Expected Output):
b= 1
test 2
c= -1
test 3
a= 1
test 4
c= 0 b= 2
test 5
錯誤結果(Wrong Output):
只想了解答案為何跟我想的不一樣
程式碼(Code):(請善用置底文網頁, 記得排版)
1 #include <stdio.h>
2 int main(int argc,char* argv[])
3 {
4 int a=0;
5 int b=1;
6 int c=-1;
7
8 if(a && ++b)
9 printf("test 1\n");
10 printf("b= %d\n",b);
11
12 if(b || ++c)
13 printf("test 2\n");
14 printf("c= %d\n",c);
15
16
17 if(b && ++a)
18 printf("test 3\n");
19 printf("a= %d\n",a);
20
21
22 if(++c || ++b)
23 printf("test 4\n");
24 printf("c= %d\tb= %d\n",c,b);
25
26 if(!c)
27 printf("test 5\n");
28 return 0;
29 }
補充說明(Supplement):
末學將這程式碼用筆想了幾遍,卻對程式碼第9,10行和第14,15行無法列印
感到疑惑,因為正常來說不管是AND或OR完之後應該都會列印出來
可是卻偏偏沒有出現test 1和test 2
想請各位前輩解惑
感謝!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.120.3.96
→
05/02 18:28, , 1F
05/02 18:28, 1F
→
05/02 18:30, , 2F
05/02 18:30, 2F
→
05/02 18:45, , 3F
05/02 18:45, 3F
→
05/02 18:50, , 4F
05/02 18:50, 4F
推
05/03 02:45, , 5F
05/03 02:45, 5F