Quoting problems unmatched quotes mismatched quotes incorrect quotes
常� 的程序代��� Quoting problems: 引号不配对 unmatched quotes, mismatched quotes, incorrect quotes Unending comments 注释没收尾 Forgetting semicolons (; ) 行尾没分号 Unmatched or mismatched braces or parentheses 括号不配对 Control strings not matching the arguments in printf(), scanf(), and other similar functions I/O函数中的格式与I/O项不一致 Forgetting & in arguments to scanf()中忘了& Loss of fractions due to use of int instead of float. 用int导致缺数 Inconsistent lengths (e. g. double vs. float) between formats and arguments in scanf() and printf(). I/O函数中格式类型不一致
1:� 法�� (syntax error) //换算后输出y的原值 main(){ int x, y, t; x, y, t printf("x=); scanf("%d", &x); printf("x="); scanf("%d", &x); printf("y="); scanf("%d", &y); t=x/y; x=x/t; printf("x=%d", x); getch(); } DEMO. C(3) DEMO. C(4) DEMO. C(8) : : : : error C 2146: syntax error : missing '; ' before identifier 'printf' warning C 4013: 'printf' undefined; assuming extern returning int error C 2001: newline in constant error C 2065: 'd' : undeclared identifier error C 2296: '%' : illegal, left operand has type 'char [11]' error C 2143: syntax error : missing ')' before 'string' warning C 4013: 'scanf' undefined; assuming extern returning int warning C 4013: 'getch' undefined; assuming extern returning int
2:运行��� (runtime error) //换算后输出y的原值 main(){ int x, y, t; printf("x="); scanf("%d", &x); printf("y="); scanf("%d", &y); t=x/y; x=x/t; printf("x=%d", x); getch(); } x=6 y=2 x=2 y=6
3:���� (logic error) //换算后输出y的原值 main(){ int x, y, t; printf("x="); scanf("%d", &x); printf("y="); scanf("%d", &y); t=x/y; x=y/t; printf("x=%d", x); getch(); } x=6 y=2 x=0
4:未�� 到的�� (unchecked error) //换算后输出y的原值 main(){ int x, y, t; printf("x="); scanf("%d", x); printf("y="); scanf("%d", &y); t=x/y; x=y/t; printf("x=%d", x); getch(); } x=6 非法访问
- Slides: 10