Things start out OK and then something goes wrong. What's happening?


#include <iostream>

int main()

{

    std::cout << "Hello World";

    return (0);

}

Source code

Hint 1: This program is one character shy of a working version.

Hint 2: It's what you don't see that's important.

Hint 3: What you don't see in the program, is invisible when the program is run.

Hint 4: When the program is finished, where does the cursor wind up?

Answer: The programmer forgot to put the newline at the end of line. As a result when the program is run on UNIX/Linux you'll see something like this:

Hello World $#

where $ is the prompt, and # represents the cursor.

If you're on MS-DOS/Windows the results will look something like:

Hello World C:>#

Again # is the cursor.

Main gallery