OK, let us begin:

A simple C++-program:

#include <stdio.h>

void main()
{
 printf("Hello world!\n");
}

And now, compile the program and start it! (See into your compiler-information how to do that).
You will see the following screen:

Hello world!
_
   <--- This is the cursor, if any

NOTE: If you use Borland C++, press Alt-F5 to see the output screen.

OK, let's see what happend:
#include <stdio.h> This line tells the computer to include another program to ours.
void main(); Here begins the main program. Later you will see what that means.
{ The { }'s mark the boundaries of the main program.
printf("Hello world!\n"); This line tells the computer to print "Hello world" to the screen.
} See above.

The ;'s must be specifyed after some commands; you must learn where to use them simply by trial&error.

The #include refers to a program where printf is defined.

printf is a command: It tells the computer to do something, in this case it tells to print anything to the screen.

Characters in ""'s are named string. Note the "\n" in "Hello world.\n". This is the replacement of the return&line feed chars. The computer doesn't do this automaticially with printf. Here is the list of all possible replacments:
\abell
\bbackspace
\fline feed
\nreturn&line feed
\rreturn
\ttabulator
\vvertical tabulator
\\\
\?question mark
\''
\""
\oooAny char in octal
\xhhAny char in hex

/* ... */: everything in this delimiters is ignored. With them you can write remarks into your programs. Strongly recommended!

  • OK, now change the code to display 'Welcome.' (without ') and then to beep. Solution

    (Note: at the end of each chapter I'll give you some tasks to do.)


    Next chapter
    Chapter overview
    Main page
    1