c语言 printf

c语言 printf,第1张

目录

返回值

实例

运行结果

参考man手册 printf(3) RETURN VALUE


返回值

printf() 返回输出元素的总长度。


实例
#include 
#include 

int main(){

	int ret;

	ret = printf("saika\n");
	printf("ret = %d\n", ret);

	ret = printf("%c\n", 'A');
	printf("ret = %d\n", ret);

	ret = printf("%d\n", 100);
	printf("ret = %d\n", ret);

	ret = printf("%.4f\n", 3.14);
	printf("ret = %d\n", ret);

	printf("\n");
	ret = printf("%d", 100);
	printf("ret = %d\n", ret);

	exit(0);
}
运行结果

测试环境: Ubuntu 21.10, gcc version 11.2.0

参考man手册 printf(3) RETURN VALUE

        Upon successful return, these functions return the number of characters

printed (excluding the null byte used to end output to strings).

       The functions snprintf() and vsnprintf() do not write  more  than  size

bytes  (including the terminating null byte ('\0')).  If the output was truncated due to this limit, then the return value  is  the  number  of characters  (excluding the terminating null byte) which would have been written to the final string if enough space had been available.   Thus, a  return  value  of  size or more means that the output was truncated. (See also below under NOTES.)

       If an output error is encountered, a negative value is returned.

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/langs/578991.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-11
下一篇 2022-04-11

发表评论

登录后才能评论

评论列表(0条)

保存