C programming tutorial

This is a tutorial for C programming language for beginners, with focus on examples and small size. WARNING: This work-in-progress article is not complete yet. Please, do not take it into consideration.

2015-02-22

A programming language is a formal language, which consists of symbols, strings or groups of symbols and rules specific to it. The main purpose of the programming language is to convey or specify instructions to a specialist machine, like a computer, for example. A list of instructions forms a program. A compiler is a set of programs and other resources that can typically translate a program from a higher level programming language, into another program that is a set of lower level instructions. In order to discern the two programs with regard to the compiler's translation process and in the most common scenario, the intial, higher level program is typically written by a human and is also called source code, while the output product of the compiler is typically intended for direct machine interpretation and is also called executable. A C compiler is needed to translate source code written in C programming language into a platform dependent executable. C compilers are available for most platforms (computer architectures and operating systems), and C programming language is widely used and very mature.

Beginner's first C program: "hello, world" example

In next few lines we will see a very small, but nonetheless legitimate, C program: so called "hello, world" example. We will compile this program; that means we will run a C compiler to produce an executable from this program. The executable is expected to print "Hello, world!" to the standard output, which is a part of the command-line interface. The source code of the program is just a plain text file. You can download it as a complete hello.c file, or create it from scratch with a text editor. Please, do not worry if you do not understand everything yet - the details will follow shortly. Here is the example:

#include <stdio.h>
int main(void)
{
    printf("Hello, world!\n");
}

Now we need to:

  1. Install and set up a compiler, or more precisely a compiler suite. This might be a laborious operation, but we only need to do it once for the very first example.
  2. Edit, prepare and have our source code available. In this first example our sorce code is just that single hello.c file.
  3. Run or invoke the compiler suite with our hello.c file as an input and check whether the compiler produced an executable or it printed any errors.
  4. If there are no errors and an executable is produced by the compiler, then run the executable to test that it works. Otherwise we need to understand the errors and possibly go back to step (2.) to edit again the source file.

Once we successfully compile and run the first example, there are some more topics to cover:

Copyright (C) 2017 embedeo.com Terms of use and legal disclaimer