Here's a typical program assigned to thousands of computer science students each year. Although apparently correct, it contains a error lurking in this simple code.
#include <iostream>
void main()
{
std::cout << "Hello World\n";
}
Hint 1: Every C++ compiler in the world will compile and execute this program without a problem.
Hint 2: The program is non-standard, yet all C++ compiler handle it "correctly". (Gives a new meaning to the term "standard" doesn't it.)
Hint 3: A couple of the newer (and better compilers) give a warning when this program is compiled. (We'd tell you the warning, but that would give things away.)
Hint 4: What is the exit code returned to the operating system.
Answer: The function main should return an
int not a void. The return value is used by the
operating system to determine if the program ran
without error.
My wife took C++ programming and this was the first program they assigned to her. (With the void.) I corrected the return to an int and she turned in her homework.
The teacher counted it wrong and changed the return back to a void. As a result I wrote a very snooty letter to the teacher quoting her chapter and verse of the C++ standard. She took it rather nicely and invited me to be a guest speaker for her class.