变量
int, long long, short, unsigned int
float, double, long double
char
运算
+, -, *, /, %
+=, -=, *=, /=, %=
++, --
- 强制转换规则
&, |, ^, !, ~, <<, >>
&&, ||
sqrt(x), fabs(x), log(x), log10(x), exp(x), pow(x, y), sin(x)
in math.h.- 浮点数比较
交互
输入输出
-
printf("%d", x)
-
%d, %f, %u, %e, %c
-
%md, %.nf
-
%%, \n, \t
-
scanf("%lf", &x)
-
scanf("%c,%c")
-
while (scanf("%d%d", &n, &m) != EOF)
-
scanf("%2d%*2d%2d", &a, &b)
-
ch = getchar()
-
putchar(ch)
-
puts("abc")
文件操作
-
program.exe < data.in > data.out
-
FILE *fopen(const char *filename, const char *mode); int fclose(FILE *fp); int fputc(int ch, FILE *fp); int fgetc(FILE *fp); int fputs(const char *str, FILE *fp); char *fgets(char *str, int n, FILE *fp); int fprintf(FILE *fp, const char *format, ...); int fscanf(FILE *fp, const char *format, ...); size_t fwrite(const void *ptr, size_t size, size_t count, FILE *fp); size_t fread(void *ptr, size_t size, size_t count, FILE *fp); FILE *freopen(const char *filename, const char *mode, FILE *stream);
-
r(b)/w(b)/a(b)(+)
流程控制
分支
-
if (...) { ... } else { ... }
-
switch (x) { case 'x1': ... break; case 'x2': ... break; default: ... break; }
循环
for (int i = 0; i < n; i++)
while (x) { ... }
rand()
and time.hcontinue, break
do { ... } while (x)
goto
高级数据类型
数组
int a[10]
int x[10] = {0}
int a[10][10]
int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
- 数组传参
memset(a, 0, sizeof a)
- 字符串输入
- 字符串输出
strlen(s)
指针
int *x
&x
*x
swap(x, y)
NULL
int (*f) (int a, int b)
- 指针是可以加整数的
结构体
struct node { int id; char name[10]; };
typedef long long int
node x = {1, "CCA"}
- 结构体嵌套
- 结构体指针
函数
int(void) func(int x, char *y) { return (x); }
assert
- 分而治之
- 变量的作用域
- 模块化