Easy Tutorial
❮ C Exercise Example24 C Examples Joseph Life Dead Game ❯

C Program Structure

Before we learn the basic building blocks of C language, let's take a look at the structure of a minimal C program, which we can refer to in the following sections.

C Hello World Example

A C program mainly includes the following parts:

Let's look at a simple code snippet that outputs the word "Hello World":

Example

#include <stdio.h>

int main()
{
   /* My first C program */
   printf("Hello, World! \n");

   return 0;
}

Next, we will explain the above program:

Compiling & Executing a C Program

Let's see how to save the source code in a file and how to compile and run it. Here are the simple steps:

Make sure your path includes the gcc compiler and that you run it in the directory containing the source file hello.c.

If you have multiple C source code files, compile them as follows:

$ gcc test1.c test2.c -o main.out
$ ./main.out

test1.c and test2.c are the two source code files.

❮ C Exercise Example24 C Examples Joseph Life Dead Game ❯