In an introductory (undergraduate or “advanced” high school) programming course, students will find their first set of difficulties in two main areas:
Syntax errors
Spelling errors
While we can classify spelling errors to be a type of syntax error, I like to differentiate the two of them to students so that they can start to understand how much of the language they are not understanding and how much is just carelessness.
Here is C++ code riddled with syntax errors and spelling errors.
How many can you find?
#include <iostream>
using namespace std;
int mymax(int a, int b)
int(main){
cout << mymax(3,7) << endl; //insertion operator should be <<
cout << mymax(12,8) << endl; //bad capitalization of mymax
return 0;
}
int mymax(int a, int b){ //semicolon does not belong
int maximum = a;
if(maximum < b) //maximum spelled incorrectly
return b; //missing semicolon
else
return a;
}
These types of mistakes are not uncommon. So if you are an instructor and see this, don’t get frustrated at your students. If you are a student and you are just getting pages and pages of errors at compile time, then don’t despair and start with the first error encountered. Work from the top of your source code and go through it line by line. More often than not, it’ll just be one or two things that have to get fixed. The above example is one of extreme carelessness and is not the norm.