In this episode of Did you know…? we take another look at some common coding mistakes.

Undeclared Functions

Extra Semicolons

Undeclared Functions

Many beginning programmers make the mistake of not declaring function.
Take the following example:

int main()
{
my_function();
}
void my_function()
{
//some code
}

A compiler walks the program from the top to the bottom, so in this case the compiler doesn’t know of my_function() until it is past main(). The result is that the first time the compiler sees my_function() it says that it doesn’t know my_function(). There are two ways to fix this. The first one is placing main() at the bottom of the program. The other is to declare the function upfront, like in the example below:

Extra Semicolons

Another common mistake beginning programmers make is putting an extra semicolon after an “if statement”,
loop or function definition. The result is that the program will not work correctly.
An example of a program that will not work correctly, because of a misplaced semicolon the program will display 10, instead of 0 to 9:

This entry was posted in Programming Tips.
You can follow any responses to this entry through the RSS 2.0 feed.
Both comments and pings are currently closed.
Tweet This! or use to share this post with others.