Joke Collection Website - Blessing messages - What is a grammatical error? What is a logical error? What is a logical error? What is a grammatical error?

What is a grammatical error? What is a logical error? What is a logical error? What is a grammatical error?

1, syntax error: This refers to the program containing statements that do not conform to the grammar rules, such as incorrect writing of keywords or symbols (printf is written as print, array element reference is written as a(2), etc. ), using undefined variables, the brackets are not equal. A program with grammatical errors cannot be compiled, so the program will not run.

2. Logical error: This refers to the error that the program has no grammatical error, and the executable program can be generated through compilation and connection, but the running result of the program is inconsistent with the expectation. For example, the value of an integer variable is out of the valid range, and the address operator is omitted in the scanf function. The subscript in the array element reference is out of bounds, and the compound statement is not used when it should be used. Because the program containing logical errors can still run, it is a kind of program error that is difficult to find and debug, so we should pay special attention to it in program design and debugging.