strlen()函数细节问题
来源:互联网 发布:911事件知乎 编辑:程序博客网 时间:2024/05/22 21:29
strlen()函数的结果值为unsigned int 类型,在进行int和unsigned int比较时,会进行数值转换,因此这种细节问题应该注意。
一般在使用strlen函数时,多数情况下是用int 定义的变量来储存strlen的值。
可以运行下面两个程序试一试:
1、
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int main(){ unsigned int a = -1; int b = 0; if(a > b)cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0;}
会发现输出结果为yes。
2、
#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;int main(){ unsigned int a = 0; int i = 0; for(; i >= a; i--) cout<<"1"<<endl; return 0;}
会发现程序一直输出1,不能结束循环。
阅读全文
0 0
- strlen()函数细节问题
- strlen函数使用问题
- 字符串处理strlen函数需要注意的一些小细节问题
- main函数细节问题
- 22-函数细节问题
- scanf函数细节问题
- 关于strlen函数的一个问题
- strlen函数
- strlen函数
- strlen() 函数
- strlen() 函数
- strlen函数
- strlen函数
- strlen函数
- strlen函数
- strlen函数
- strlen函数
- strlen函数
- html两个div浮动后下一个div怎么换行的问题
- 垃圾CSDN 吞我博客 还封我号 我必须用小号骂你
- 多线程下载加安装程序加RxJava加Fresco
- 数据结构实验之二叉树二:遍历二叉树
- Java十一周作业
- strlen()函数细节问题
- 高性能服务器编程——多进程编程
- Magic Powder
- Caffe学习笔记6--前4课知识点备忘
- Python中的bisect
- Angular 4入门教程系列:12:TypeScript:类与接口
- Spring实战-装配bean
- 软件工程(C编码实践篇)学习总结
- H01 C++面向对象高级编程下作业解析