1,延续以前在Ubuntu操作系统下使用word记录安装及配置命令的经验,在此文档下收集和整理敲代码过程中遇到的各种报错,以便总结经验,吸取教训。

2,由于Python和C语言同时学习,不必拘泥于语言,而是提升自己排除错误的能力;

1,报错

  1. File "c:\Users\Tylor\Documents\Python\Leecode\quick_sort.py", line 15, in
  2. partition(li, 0, len(li - 1))
  3. TypeError: unsupported operand type(s) for -: 'list' and 'int'
  4. PS C:\Users\Tylor\Documents\Python> python -u "c:\Users\Tylor\Documents\Python\Leecode\quick_sort.py"

出现原因:输出语句计算字符串长度的时候,将len(list) - 1 写成了len(list - 1)
image.png

2.文章阅读

fork() system call

the meaning of returned value and the process of calling

image.png
the recursion of fork()

image.png
Important: Parent process and child process are running the same program, but it does not mean they are identical. OS allocate different data and states for these two processes, and the control flow of these processes can be different.

3,代码编写不规范造成的数值溢出

  1. /*day_mon1.c* -- 打印每个月的天数*/
  2. // 20210320 21:20
  3. #include <stdio.h>
  4. #define MONTHS 12
  5. int main(void)
  6. {
  7. int days[MONTHS] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  8. int index;
  9. for (index = 0; index < MONTHS; index++);
  10. printf("Month %2d and %2d days.\n", index + 1, days[index]);
  11. return 0;
  12. }

image.png

常见报错: stray ‘\357’ in program

出错原因:分号应该为英文,实际输入了中文;

  1. 具体分析产生原因: 在编程中,由于打字的快速,按下ctrl键后紧接着按下了space键,
  2. 由于按下两个键的间隙比较短,导致系统误检测到ctrl + space信号,将输入法从半角切换到全角。 该错误是指源程序中有非法字符,需要将非法字符去掉。
  3. 一般是由于coder使用中文输入法或者从别的地方直接复制粘贴代码造成的。