c++ 为什么strcmp返回int而不是char?

栏目: C++ · 发布时间: 6年前

内容简介:更一般地,int是优选的,用于传递和返回简单的数值,因为它被定义为这样的值的“自然”大小,并且在一些平台上比较小的类型更有效.代码日志版权声明:翻译自:http://stackoverflow.com/questions/30487800/why-strcmp-returns-int-but-not-char
据我所知,变量类型(如char,int等)之间的唯一区别是它们占用的内存量.我猜他们在调节他们所持有的变量代表什么方面没有任何作用.如果是这样,在 here

,我看到以下strcmp:

The strcmp function compares the string s1 against s2, returning a  value that has the same sign as the difference between the first  differing 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


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Coming of Age in Second Life

Coming of Age in Second Life

Tom Boellstorff / Princeton University Press / 2008-04-21 / USD 29.95

The gap between the virtual and the physical, and its effect on the ideas of personhood and relationships, is the most interesting aspect of Boellstorff's analysis... Boellstorff's portrayal of a virt......一起来看看 《Coming of Age in Second Life》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

MD5 加密
MD5 加密

MD5 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具