Section outline

  • This Java Fundamental Course is designed for beginners to advanced programmers who are striving to learn Java Programming. We have provided numerous practical examples to explain the concepts in simple and easy steps. This tutorial has been prepared and reviewed by experienced Java Programmers at Tutorials Point and best effort has been put to make it useful for the students and Java developers.

  • The compilation is the process of converting the source code of the C language into machine code. As C is a mid-level language, it needs a compiler to convert it into an executable code so that the program can be run on our machine.

    The C program goes through the following phases during compilation:

    1. Pre-processing
    2. Compilation
    3. Assembly
    4. Linking

    compilation process in c

    How do we compile and run a C program?

    We first need a compiler and a code editor to compile and run a C Program. The below example is of an Ubuntu machine with GCC compiler.

    Step 1: Creating a C Source File

    We first create a C program using an editor and save the file as filename.c

     $ vi filename.c

    We can write a simple hello world program and save it.

    Step 2: Compiling using GCC compiler

    We use the following command in the terminal for compiling our filename.c source file

     $ gcc filename.c –o filename

    We can pass many instructions to the GCC compiler to different tasks such as:

    • The option -Wall enables all compiler’s warning messages. This option is recommended to generate better code. 
    • The option -o is used to specify the output file name. If we do not use this option, then an output file with the name a.out is generated.

    If there are no errors in our C program, the executable file of the C program will be generated.

    Step 3: Executing the program

    After compilation executable is generated and we run the generated executable using the below command.

     $ ./filename