atoi()函数

C 库函数 int atoi(const char *str) 把参数 str 所指向的字符串转换为一个整数(类型为 int 型)
函数原型:int atoi(const char *str);
头文件:#include <stdlib.h>

//以下程序输出结果为 1
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
int main()
{
	char a[] = "-100";
	char b[] = "101";
	int c;
	c = atoi(a) + atoi(b);
	printf("c = %d\n", c);
	return 0;
}
发布了68 篇原创文章 · 获赞 4 · 访问量 1192

猜你喜欢

转载自blog.csdn.net/CLZHIT/article/details/104041529