关于字符型数据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 }

没输出:

 

posted @ 2022-09-18 22:58  balabalahhh  阅读(67)  评论(0编辑  收藏  举报