# 你真的理解“她们”吗？

1.printf()

2.scanf()

1.printf()

printf函数也是有返回值的。

Return Value

Each of these functions returns the number of characters printed, or a negative value if an error occurs.

KiKi写了一个输出“Hello world!”的程序，BoBo老师告诉他printf函数有返回值，你能帮他写个程序输出printf(“Hello world!”)的返回值吗？

``````#include <stdio.h>
int main()
{
printf("n%d", printf("Hello world!"));
return 0;
}``````

2.scanf()

scanf()库函数为读入函数，从键盘上读入，读入时先储存到一个名为缓冲区的储存区域，遇到'n'（即键盘上的Enter回车键）停止读入，下面就开始sacnf从缓冲区进行数据的读取，在遇到空格和非打印字符时停止读入，剩下的数据仍在缓冲区中储存着，等待着下一次的读取。

## 描述

### 输出描述：

看下面的代码：

``````#include <stdio.h>
int main()
{
float cj[5];
float sum = 0;
int n;
for (n = 0; n < 5; n++)
{
scanf("%f", &cj[n]);
sum += cj[n];
}
for (n = 0; n < 5; n++)
{
printf("%.1f ", cj[n]);
}
printf("%.1f", sum);
return 0;
}``````

其实是没有必要的：

``````#include <stdio.h>
int main()
{
float cj;
float sum = 0;
int n;
for (n = 0; n < 5; n++)
{
scanf("%f", &cj);
sum += cj;
printf("%.1f ", cj);
}
printf("%.1f", sum);
return 0;
}``````

Return Value

Both scanf and wscanf return the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned. A return value of 0 indicates that no fields were assigned. The return value is EOF for an error or if the end-of-file character or the end-of-string character is encountered in the first attempt to read a character.

EOF的值是多少呢？我们转到定义：发现是-1

THE END

)">