Basic Standard C Programming
Introduction and Example
The best way I've found to learn the C programming language is by example. Read about this example first and try to understand it. If you need to know how to run the program, look at the compilers tutorial for Windows or Linux. In this tutorial, I will explicitly write down the line numbers so I can explain them later, but in a real program you cannot include the line numbers in the line or the compiler will not understand the program. If you want a copy of this program, download it at the bottom of this page.
1. #include <stdio.h>
2.
3. int main( int argc, char *argv[] )
4. {
5. printf( "Hello World!\n" );
6. getchar();
7. return 0;
8. }
Line 1: This line includes part of the standard C library that will allow us to display characters to the console (command prompt). This is the reason why we can use the "printf" function in line 5.
Line 2: This blank line makes the program easier to read.
Line 3: "main" is a thing called a function. It is the 'entry point' for every program written in C, so a C program without a "main" will not compile or run. When you double click the icon of a C program, "main" is the place where the program starts running. You can ignore this line for now because it is always the same in every C program you will see.
Lines 4 & 8: These braces designate lines 5, 6 and 7 as being part of the "main" function.
Line 5: printf is a call into the Standard C Library that will display characters to the console, aka the command prompt.
Line 6: getchar is another call into the Standard C Library. In this case, we are using it to pause the program so it doesn't exit right away. The program will halt at this line until the "enter" key is pressed.
Line 7: Every "main" function in C needs to return a value back to the operating system that called it to say "everything's ok" or "something failed." "return 0;" will let the operating system know everything ran fine.
When you run this program, you will see "Hello World!" displayed at the command prompt.
Downloads
About the Author
Grant Dryden works in the defense industry as a computer engineer. He writes software in C and C++ for embedded systems as well as firmware in VHDL. He has a Bachelor of Science in Computer Engineering and is currently working towards a a Master of Science in Information Security.

