测试代码:
#include <stdio.h>
#include <string.h>
using namespace std;
int main() {
char s[] = "12345";
printf("%d\n", atoi(s));
printf("%d\n", atoi(s+1));
printf("%d\n", atoi(s+2));
printf("%d\n", atoi(s+3));
printf("%d\n", atoi(s+4));
}
测试结果:
12345
2345
345
45
5
--------------------------------
Process exited after 0.1735 seconds with return value 0
请按任意键继续. . .
可见用这种格式的参数时返回的是从输入的指针开始到字符串末尾的字符串。
本文通过测试代码展示了C语言中atoi函数的使用方法,详细解释了如何从字符串中转换整数,以及atoi函数如何处理从指定位置开始的字符串。
5万+

被折叠的 条评论
为什么被折叠?



