Step One  Hello World

Where do we start? One of the common practices is to write a program that will display "Hello World" on the screen. If you are successful, you will have learned how to use the emacs editor and save your source code, how to use the GNU c++ compiler, how to run the program you compiled, and just how big the executable code size is for such a tiny program.
Sample program:

( 1)   // Program Name: hello.cpp
( 2)   // Description: Display something on the screen
( 3)   // Author: Duck Dodgers
( 4)   // Date: September 1, 2005
( 5)
( 6)   #include <iostream>  //this is needed for C++ I/O
( 7)   #include <string>    //this will be needed for strings later on
( 8)   using namespace std;
( 9)
(10)   int main(void) {
(11)     //display something on a line by itself
(12)     cout << "Hello world!" << endl;
(13)     return 0;
(14)   }
Anatomy of the program:

After typing the program source code in using emacs (without the line numbers!), save the file as hello.cpp and exit emacs. From the unix prompt, type:

     c++ -o hello hello.cpp

c++ is the GNU C++ compiler. The -o option means to name the executable file hello. The C++ compiler compiles the source program called hello.cpp.

To execute the program after it successfully compiles, type ./hello at the UNIX prompt. To see how big the program is, type ls -la to see the size of the executable program called hello.


This size should be significant when you consider that the computer which got astronauts to and from the moon started out with the equivalent of about 20,000 bytes of storage!


 

Advance to Step Two

Return to the Table of Contents