#2 阮一峰的 C 语言教程学习

2021-09-07
  1. https://wangdoc.com/clang/
  2. GitHub, https://github.com/wangdoc/clang-tutorial

目录

  • 1. 简介
    历史,标准,Hello World
  • 2. 基本语法
    基本语法,printf 格式化
  • 3. 变量
  • 4. 运算符
  • 5. 流程控制
  • 6. 数据类型
    1. 整型的不同进制表示
    2. limits.h 中的极限值
    3. 关于布尔型,int, _Bool(C99, int 别名), bool/true/false (stdbool.h)
    4. 字面量后缀 (l, ll, u, f)
    5. 类型转换
    6. 可移植类型 (stdint.h)
  • 7. 指针
  • 8. 函数
  • 9. 数组
  • 10. 字符串
  • 11. 内存管理
  • 12. struct 结构
  • 13. typedef 命令
  • 14. Union 结构
  • 15. Enum 结构
  • 16. 预处理器
  • 17. I/O 函数
  • 18. 文件操作
  • 19. 变量说明符
  • 20. 多文件项目
  • 21. 命令行环境
  • 22. 多字节字符
  • 23. 标准库
    • 23.1. assert.h
    • 23.2. ctype.h
    • 23.3. errno.h
    • 23.4. float.h
    • 23.5. inttypes.h
    • 23.6. iso646.h
    • 23.7. limits.h
    • 23.8. locale.h
    • 23.9. math.h
    • 23.10. signal.h
    • 23.11. stdint.h
    • 23.12. stdlib.h
    • 23.13. stdio.h
    • 23.14. string.h
    • 23.15. time.h
    • 23.16. wchar.h
    • 23.17. wctype.h

关键字

// 数据类型 12
short   int         long    double  float
char    struct      union   enum    typedef
signed  unsigned

// 变量 6
auto    register    extern  const   volatile
static

// 函数 2
void    return

// 控制语句 11
if      else    for     continue    while  do
switch  case    default goto        break

// 其他 1
sizeof

数据类型

  • 整数:short, int, long, long long
  • signed, unsigned
  • 浮点数:float, double
  • 字符:char, char *
#include <stdio.h>

int main(){
    printf("size of int:         %2ld\n", sizeof(int));
    printf("size of short:       %2ld\n", sizeof(short));
    printf("size of long:        %2ld\n", sizeof(long));
    printf("size of long long:   %2ld\n", sizeof(long long));
    printf("size of float:       %2ld\n", sizeof(float));
    printf("size of double:      %2ld\n", sizeof(double));
    printf("size of long double: %2ld\n", sizeof(long double));
    printf("size of char:        %2ld\n", sizeof(char));
}
$ uname -a
Linux dell 5.11.0-34-generic #36-Ubuntu SMP Thu Aug 26 19:22:09 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

$ gcc --version
gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc /tmp/test.c -o /tmp/test && /tmp/test
size of int:          4
size of short:        2
size of long:         8
size of long long:    8
size of float:        4
size of double:       8
size of long double: 16
size of char:         1