C语言atoi函数以“字符数组指针+序号”为参数时的返回情况

测试代码:

#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
请按任意键继续. . .

可见用这种格式的参数时返回的是从输入的指针开始到字符串末尾的字符串。

发布了43 篇原创文章 · 获赞 3 · 访问量 1367

猜你喜欢

转载自blog.csdn.net/Zen_Ivan/article/details/105474281