チタン合金 さんが書きました:if(c >= '0' && C <= '9')のここは、'0'の部分は、文字定数ですよね?
文字定数って条件式に使えるものなんですね。
文字定数(N3337 2.14.3 Character literals)はliteralの一種であり、literalはprimary expression(N3337 5.1)なので、式に使えます。
条件式は式の一種なので、当然使えます。
チタン合金 さんが書きました:あと配列のcnt[c - '0']++; これは何をしているのでしょうか?
cに代入された数字の文字コードを対応する数値に変換し、配列のその数値を添え字とする要素に1を足しています。
C++の規格で数字の文字コードは直感的な順番で連続しているとされているので、この式で数字を数値に変換できます。
N3337 2.3 Character sets さんが書きました:
1 The basic source character set consists of 96 characters: the space character, the control characters repre-
senting horizontal tab, vertical tab, form feed, and new-line, plus the following 91 graphical characters:
[table=margin-left:2em;][tr=][td=font-family:monospace;]a b c d e f g h i j k l m n o p q r s t u v w x y z[/td][/tr]
[tr=][td=font-family:monospace;]A B C D E F G H I J K L M N O P Q R S T U V W X Y Z[/td][/tr]
[tr=][td=font-family:monospace;]0 1 2 3 4 5 6 7 8 9[/td][/tr]
[tr=][td=font-family:monospace;]_ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ∼ ! = , \ " ’[/td][/tr][/table]
(中略)
3 (中略) In both the source and execution basic character sets, the value of each character after 0 in the
above list of decimal digits shall be one greater than the value of the previous.
今回のオペランドはint型なので、後置++演算子はオペランドの値をそれに1を足したものに書き換えます。
N3337 5.2.6 Increment and decrement さんが書きました:
The value of the operand object is modified by
adding 1 to it, unless the object is of type bool, in which case it is set to true.
N3337