C - for 408

`***1 运算符优先级

! > 算术运算符 > 关系运算符 > && > || > 赋值运算符 (!, &&, || 都是逻辑运算符)

`2 短路写法

1
2
3
4
5
int i=0;
i && printf("You Can't See ME !\n"); // 不会执行&&后边的

int j=1;
j || printf("You Can't See ME !\n"); // 这也是短路运算

`3 左值右值

1
a+25 = b; // 这会导致编译错误

`4 数组特点

  • 具有相同的数据类型
  • 使用过程中需要保留原始数据

`5 <string.h>

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
#include <string.h>

int main(void) {
    int len;
    char c[20];
    char d[100] = "world";
    gets(c); // gets()函数
    puts(c); // puts()函数
    printf("len C = %d\n", strlen(c));

    strcat(c, d); // 把 d 中的字符串拼接到 c 中
    puts(c);
    strcpy(c, d); // 把 d 中字符串 拷贝 到 c
    puts(c);
    int iscmp = strcmp(c, d); // 比较字符串大小 比较ASCII码 相等返回0 c>d返回正值 c<d返回负值
    printf("iscmp = %d\n", iscmp);
    return 0;
}