目录
返回值
实例
运行结果
参考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 VALUEUpon 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.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)