C – Hello World!

InPursuitThe first program most people learn to write in any computer language is a program called “Hello World!” An online programmer friend recently mentioned that many of the basics you encounter in the programming language are built into “Hello World!” It got me thinking and I decided to post a short example of this classic program with explanations.

Yes, this program can be found many places and I’m reinventing the wheel by writing it. However, every person explains differently and, where someone else may have confused you, I may be the person to explain something in a way you will understand. Also, I find that communicating concepts helps me understand them better.

Here’s the program in C.

#include <stdio.h>

int main() {

   printf("\n\nHello World!\n\n");
   return 0;


The first line we encounter is:

#include <stdio.h>

This instruction is called a pre-processor directive. It loads the standard input/output library into the program. Part of the raw power of C is the low level control it gives you over the tasks your computer accomplishes and a good portion of this power is derived from the functionality that libraries provide. The most basic (and most often used) input and output are the keyboard and monitor, used to input and output data (interact with the program).

Libraries contain pre-programmed functions that expand what you can do with a computer language and “stdio.h” is one of the standard libraries included in the C language. You can also write functions of your own to complete repetitive tasks. In fact, there is one function that every C program must have.

Here’s the function that every C program must have to compile and run.

int main() {


Programmers refer to this function as “main.” The “int” refers to the type of data that the function returns when it exits, an integer. Functions are capable of returning different types of data or no data at all. A function that returns no data starts with “void” instead and there are other types. I have seen programs that start “main” with “void” instead of “int” but not all compilers will compile them. It is standard to start “main” with “int” and return an integer when the program exits, using a “return” statement.

The actual function is the word “main,” followed by parentheses and a pair of curly braces. The braces can contain data and commands. You can place data inside the parentheses that you want passed to the function. Our example contains a couple of lines of code inside the braces but the parentheses are empty. That is because we are not passing any outside data to “main.”

Here is an example.

return 0;

The “return” statement is used to return data when the function completes. It’s standard for the “main” function to return a zero when it completes, indicating that the program completed and exited normally. The “;” at the end of the line is like the period at the end of a sentence in English. It notifies the compiler that this is the end of the statement.

The one line of the program we haven’t discussed is:

printf("\n\nHello World!\n\n");

This line calls the “printf” function and tells it to print the “Hello World!” message to stdout, which is usually the computer screen. The printf() is the complete function (you only add the braces to functions in which you are writing the commands), everything between the parentheses is the data you are passing to the function and the semicolon at the end of the line tells the compiler this is the end of the statement.

Everything between the double quotes is a string of characters sent to the “printf” function. You can pass data in other ways but, when you are typing a string of characters to send, you must enclose them in double quotes. The “\n” is a newline character and printf() will respond by moving down a line on your screen before writing the message. In this case, the message is printed two lines down from the command used to call the program and is followed by two more new lines, ensuring that there is space before and after the program’s output. This makes the output more readable because it is not surrounded by clutter.

I hope you enjoyed the article. I’m looking forward to any comments, questions or corrections you may have.

Pursuing a Dream Written in Code

What is this dream?

It all started years ago, when I was in my late teens. My friend, Bill, had a computer. I was enthralled with the things he could do with it. It was amazing to see the things he programmed on his Apple computer. I think it was the iie but I don’t remember the model number for sure. Unfortunately, Bill didn’t see his dream of being a programmer. He died of leukemia when he was about 18 or 19 years old. I think he would have been a great contributor to excellence in the computer-driven world we have today.

I’ve wandered my own path in life but computers and music have always been of prime importance. I tried computer programming when I was younger but the math classes discouraged me. I’ve taught music forever, own and operate my own business that does a variety of media production (including music and video) and teaches music and art in our local community. I worked as a technical writer for a number of years, went to school for music and to learn the business of the entertainment industry, and also write and manage the company’s web pages. My interest in programming has never left but my own near death experience in November 2012 has given me an enhanced appreciation of life and the impetus to do the things I’ve wanted to do for a long time.

So, Here’s the Plan

I am currently doing websites in PHP and HTML (my strongest web languages), with MySQL and CSS (necessary companions) and a smattering of Javascript (my weakest language and the closest to being my nemesis). I will be working to update these skills as I go in my daily work.

The areas of interest I have in learning and using additional languages include refreshing my knowledge of C, continuing in C++ and getting farther with Java than I have gone. I learned C years ago but got stuck on pointers. How silly that seems now. I didn’t get very far with C++; I’m going through the tutorial now and can tell you that a couple of years makes a big difference. I stopped for a while in Java but need to go through all the object oriented stuff more fully.

Will You Join Me on My Journey?

I will be posting about my journey here as I strive to become a better programmer. It doesn’t mean I will only post about computer programming. I will also be posting about music, my other great passion, and the two great things you are never supposed to discuss in polite company, namely, religion and politics. You are welcome to join me as I continue a journey that is years in the making. There may be wisdom and wit; that often happens when I’m at my best. You may also, from time to time, catch me at my worst. I hope you will gain something from every minute of it.