Thursday, August 11, 2011

Types of Errors

There are two primary types of errors: syntax errors and semantic errors.

A syntax error occurs when you write a statement that is not valid according to the grammar of the C++ language. This happens a lot through typos or accidental omission of keywords or symbols that C++ is expecting. Fortunately, the compiler will generally catch syntax errors and generate warnings or errors so you know what the problem is.

Once your program is compiling correctly, getting it to actually produce the result(s) you want can be tricky. A semantic error occurs when a statement is syntactically valid, but does not do what the programmer intended. Unfortunately, the compiler will not be able to catch these types of problems, because it only knows what you wrote, not what you intended.

No comments:

Post a Comment