Here's a typical program assigned to thousands of computerscience students each year. Although apparently correct,it contains a error lurking in this simple code.
#include <stdio.h>void main(){ printf("Hello World\n");}Hint 1: Every C compiler in the world will compileand execute this program without a problem.
Hint 2: The program is non-standard, yet all C compilerhandle 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 warningwhen 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 operatingsystem.
Answer: The function main should return anint 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 the C++ version of thisprogram was the first programthey assigned to her. (With the void.) I correctedthe 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 speakerfor her class.