Program name:  printing.c

Language features of C contained in "printing.c"
 translation of C code to machine code
 preprocessing - incorporating outside code into your code
 functions - in the form of the one called "main" and the other one called "printf"
 values being given to, and given by, functions
 language syntax (in this case, the use of semi-colons)

Function:  prints the phrase "Hello World!" on the monitor

Source code:

 

Explanations:

C divides programs into subunits called functions. I wrote the function named "main" which must always be present in a C program. You type the name followed by a pair of parentheses (line 3). Below that you put a pair of curly braces (lines 4 and 7). Between them you put whatever code you like; that code belongs to the function (lines 5 and 6). This program contains, indirectly, a second function. I didn't write that one. Its name is printf. The code for it is elsewhere, and my line 1 references a file that defines where to get that code. When bcc32 runs, it fetches that foreign code and sticks it into my program before going ahead. It's as if I wrote it, but I don't have to. I borrow and include it instead. If the code for the printf( ) function were 100 lines long, my single line 1 would expand to 100 lines and my "main( )" declaration would be pushed down to line 102 in the "preprocessed" version.

functions can be given values, or not. The printf( ) function is for printing something. So it must be given what you want it to print. You give a function some value by putting the value between the parentheses in the name of the function when you call it (line 5). Functions can also give values back. We'll talk about that later.

Specific to the C language, you must end most lines with a semicolon. It's strict about that.

To do:

Key this program in, using a text editor (in Windows Notepad or Notepad++ will do; if you use Wordpad or Word be sure to save what you type in a "text" type file). Save it in a file named "printing.c". Then, in order to convert it into form that contains correct Intel machine instructions, thus enabling the computer to run it, bring up the Windows command box and give this command:

bcc32  printing.c

Alternatively use a browser to go to a C compiler web site. Cut your program's text from the text editor and paste it into the appropriate place in the web site. Tell the web site to compile (there's generally a button that says "compile" or maybe "run".)

If there are no error messages, a new file named "printing.exe" will result. Then give the command:

printing.exe

You will see "Hello World!" appear printed on the monitor.

Try the same thing after removing some things from the program. What if the first line is missing? What if the semicolon is missing? What if the 6th line is missing? Try all of these 3 variations and see what kind of problems result.

After you get this program to run, I would like you to write a slightly different alternative program that prints a declaration of your name in the form, for example, "Hello, my name is David Morgan." I will ask you to provide me your program. The point is to make you familiar with the steps involved in this kind of traditional compiled programming.