关于字符串比较函数strcmp返回值的问题

字符串比较函数strcmp

格式:  strcmp(字符数组名1,字符数组名2)
功能:按照ASCII码顺序比较两个数组中的字符串,并由函数返回值返回比较结果。
    字符串1=字符串2,返回值=0;
    字符串2〉字符串2,返回值〉0;
    字符串1〈字符串2,返回值〈0。

本函数也可用于比较两个字符串常量,或比较数组和字符串常量。

ANSI标准规定,返回值有正数,负数,0.而确切数值是依赖不同的C实现的。

Return Value

Returns an integral value indicating the relationship between the strings:
return valueindicates
<0the first character that does not match has a lower value in ptr1 than in ptr2
0the contents of both strings are equal
>0the first character that does not match has a greater value in ptr1 than in ptr2


1.一般来说,返回值会是:1 0 -1



2.有些会把两个字符的ASCII码之差作为比较结果由函数值返回。





  • 31
    点赞
  • 52
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值