c語言中的digit怎麼用
來源:魅力女性吧 2.79W
digit[ch-Ɔ']++ 在c語言中是一個語句。
digit 是一個一維數組, ch-Ɔ' 得到一 個 數值,作為下標
digit[ch-Ɔ'] 是一個數組元素。
++ 是 後綴 ++,出了表達式後變量自增1運算, 即 讓該數組元素 的值 增加 1:
digit[ch-Ɔ']++ 就是 digit[ch-Ɔ'] = digit[ch-Ɔ'] + 1
ch 是一個字符變量,例如 char ch=Ƌ' Ƌ' 的 ASCII 值,減去 Ɔ' 的 ASCII 值 等於算術值 5。 (Ɔ',Ƌ' 這些單引號括起的 叫 字符常量,數值等於該字符的ASCII 值)。
原語句就成了 digit[5] = digit[5] + 1
程序例子:
#include <stdio.h>
int main()
{
int digit[10]={1,2,3,4,5,6,7,8,9,10}
int i
char ch=Ƌ'
digit[ch-Ɔ']++
for (i=0i<10i++) printf("%d ",digit[i])
return 0
}
輸出:1 2 3 4 5 7 7 8 9 10
可以看出 digit[5] 原來等於 6, 自增1後 變 7。