c++ 為什麼strcmp返回int而不是char?
,我看到以下strcmp:
The strcmp function compares the string s1 against s2, returning avalue that has the same sign as the difference between the firstdiffering pair of characters (interpreted as unsigned char objects,then promoted to int).
我想問為什麼結果提升到int?由於字元被比較,它們的差異適用於所有情況下的字元.那麼結果是不是在結果的最後簡單地追加0的結果呢?那麼為什麼要這樣做呢?
更一般地,int是優選的,用於傳遞和返回簡單的數值,因為它被定義為這樣的值的“自然”大小,並且在一些平臺上比較小的型別更有效.
程式碼日誌版權宣告:
翻譯自:http://stackoverflow.com/questions/30487800/why-strcmp-returns-int-but-not-char