0

再见strlen函数

 1 year ago
source link: https://blog.51cto.com/u_15740457/5753495
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

再见strlen函数

精选 原创

hanwangyyds 2022-10-13 14:53:59 博主文章分类:笔记 ©著作权

文章标签 字符串 srelen函数 文章分类 C/C++ 编程语言 yyds干货盘点 阅读数151

功能:计算字符串长度。

再见strlen函数_srelen函数

计算第一种常量字符串,直接默认后面以\0结尾,输出结果是6;但第二种对数组的字符串进行计算,输出结果却是随机值。

原因:这两种计算方法没有区别,但是数组,后面没有默认\0的出现,所以一直寻找,生成随机值。

返回类型:无符号整型

再见strlen函数_srelen函数_02

此时输出结果为hehe;因为3-6本应该是-3,是负数,但两个无符号整型相减的结果仍然是无符号整型,所以输出结果仍为正>0

在网上查询到strlen的返回类型size_t==unsigned int!!!

  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK