钱平需要知道的知识点(上课视频讲解的)
文章目录
一、scanf 和 printf
scanf 和 printf 都是 库函数
scanf 的作用是:输入数据,数据从键盘读取到内存中。
取地址运算符:&
printf 的作用是:输出数据,数据从内存打印(输出)到屏幕上。
%d : 整数
%c : 字符
%s : 字符串
%f :float
%lf : double
%p : 地址的打印
使用的时候要包含 头文件 #include<stdio.h>
二、scanf
打开 https://cplusplus.com/ 网站 (使用 旧版),搜索 scanf 函数
On success, the function returns the number of items of the argument list successfully filled. This count can match the expected number of items or be less (even zero) due to a matching failure, a reading error, or the reach of the end-of-file.
If a reading error happens or the end-of-file is reached while reading, the proper indicator is set (feof or ferror). And, if either happens before any data could be successfully read, EOF is returned.
If an encoding error happens interpreting wide characters, the function sets errno to EILSEQ.
如果成功,函数返回参数列表中成功填充的项数。由于匹配失败、读取错误或到达文件末尾,此计数可以匹配预期的项数,也可以更少(甚至为零)。
如果在读取过程中发生读取错误或到达文件末尾,则设置适当的指示器(feof或ferror)。并且,如果在成功读取任何数据之前发生任何一种情况,则返回EOF。
如果在解释宽字符时发生编码错误,函数将errno设置为EILSEQ。
1. scanf 函数 返回的是 读取到的数据的个数
int main()
{
int a = 0;
int b = scanf("%d", &a);
printf("%d\n", b);
return 0;
}
int main()
{
int a = 0;
int b = 0;
int c = scanf("%d %d", &a, &b);
printf("%d\n", c);
return 0;
}
2. 如果 scanf 函数读取失败,会返回 EOF
3. CTRL + Z 让程序停下
(下面 典型例题 有详细讲解)
由于VS编译器存在漏洞,需要连续按 三次 CTRL + Z,才能让程序停止。
在其他编译器下,正常按一次就可以了。
int main()
{
int a = 0;
while (scanf("%d", &a)!= EOF)
{
printf("ok\n");
}
return 0;
}
三、典型例题
-
题目:
描述
据说智商140以上者称为天才,KiKi想知道他自己是不是天才,请帮他编程判断。输入一个整数表示一个人的智商,如果大于等于140,则表明他是一个天才,输出“Genius”。输入描述:
多组输入,每行输入包括一个整数表示的智商。输出描述:
针对每行输入,输出“Genius”。问题关键:多组输入
然而,我的答案是:单次输入
int main()
{
int iq = 0;
int a = 0;
while ((a= scanf("%d", &iq))!=EOF)
{
if (iq >= 140)
{
printf("Genius\n");
}
}
return 0;
}
或者
#include <stdio.h>
int main()
{
int n = 0;
while(scanf("%d", &n) != EOF)
{
if(n>=140)
printf("Genius");
}
return 0;
}
四、
有的电脑就是没有 这个绿色标志,在第二节课的时候,老师讲过了
不碍事的
五、
六、形式参数,实际参数
七、数组
先了解这些内容就可以,之后会具体深入去学习的
八、
C语言中如何表示 真假 ?
0 表示 假
非0 表示 真
举例:
-1是真还是假?
答:
真,因为 非0 就是真
单目运算符 ! 逻辑反操作
#include<stdio.h>
int main()
{
int a = 0;
printf("%d\n", !a);
return 0;
}