next up previous
Next: Testing a Program Up: Overview of C++ Previous: Console Input

Syntax Errors

While programming it is quite easy to accidently type something incorrectly when entering the code into the computer. Fortunately, if you enter something incorrectly into your program, the compiler will report a syntax error message when it tries ti compile it. As in spoken languages, computer languages has rules (Punctuation marks, grammars) that need to be followed. These rules are called syntax. In C++ the syntax uses semicolons, parentheses, braces and many other characters. When a programmer forgets or misuse one of these characters, the C++ will display an error message on the screen that describes the error. Most C++ compilers attempt to make sense out of the source code no matter what is written in it. For this reason, the error that is reported may not always reflect the actual cause of the problem.

Many C++ compilers report not only actual errors, but also warnings. The C++ language was designed to be very forgiving and to allow virtually anything that is syntactically correct to be compiled. Suspicious statements are reported as warning and it is to the programmer to investigate the seriousness of these warnings.

A program may be syntactically correct and no warning reported but still give a wrong answer, is a program that contain a bug. A bug is either a programming error (i.e. + instead of -) or a logical error where you cannot perform an operation sequence in a logical manner. These errors need to be investigated by testing the program.



 
next up previous
Next: Testing a Program Up: Overview of C++ Previous: Console Input
Yousef Haik
2/23/1998