关于字符型数据c == 1
1.这里的数字与ASCII码是对应的
1 #include <stdio.h> 2 3 int main(){ 4 char s[7] = {1,2,0,2,0,3}; 5 if(s[2] == 0) printf("%d",s[2] - '0'); 6 return 0; 7 }
输出为 -48:
1 #include <stdio.h> 2 3 int main(){ 4 char s[7] = {1,2,0,2,0,3}; 5 if(s[2] == '0') printf("%d",s[2] - '0'); 6 return 0; 7 }
没输出:
2.这里的数字与ASCII码不对应
1 #include <stdio.h> 2 3 int main(){ 4 char s[7] = {'1','2','0','2','0','3'}; 5 if(s[2] == '0') printf("%d",s[2] - '0'); 6 return 0; 7 }
输出为 0:
1 #include <stdio.h> 2 3 int main(){ 4 char s[7] = {'1','2','0','2','0','3'}; 5 if(s[2] == 0) printf("%d",s[2] - '0'); 6 return 0; 7 }
没输出: