C Programming for Beginners – Chapter 03 : Compilation and Execution in C

Free eBooks for Beginners

Compilation and execution are two key steps in the process of developing a C program. Compilation is the process of converting the source code of a program into machine code, which can be executed by the computer. Execution is the process of running the compiled code on a computer. In this tutorial, we will go over the steps involved in compiling and executing a C program.

First, let’s talk about compilation. To compile a C program, you will need a C compiler, such as GCC (GNU Compiler Collection). GCC is a popular open-source compiler that is widely used by C programmers. To compile a C program, you will need to open a terminal or command prompt and navigate to the directory where the C source code file is located. Then, type the following command:

gcc hello.c -o hello

This command compiles the hello.c file and creates an executable file called hello. The -o option is used to specify the name of the output file.

Once the C program is compiled, it can be executed. To execute a C program, simply type the following command in the terminal or command prompt:


This command runs the hello program and displays the output on the screen.

It’s important to understand that C programs are compiled and executed on a line-by-line basis. This means that the compiler will process each line of code in the program, and if it encounters an error, it will stop the compilation process and display an error message. It’s up to the programmer to correct the error and try compiling the program again.

There are two types of errors that can occur in C programming: syntax errors and logical errors. Syntax errors occur when the C code doesn’t conform to the syntax rules of the language, such as forgetting to include a semicolon at the end of a statement. Logical errors occur when the code runs without producing an error message, but the output is not what you expected.

To debug a C program, you can use a debugger, which is a tool that allows you to step through the code line by line and see what’s happening at each step. This can be helpful in identifying logical errors and fixing them.

In summary, compiling and executing a C program is a simple process that involves using a C compiler and a terminal or command prompt. Once the program is compiled, it can be executed, and the output will be displayed on the screen. If errors occur during the compilation or execution process, the programmer can use a debugger to step through the code and identify the issue. With practice, you will become proficient in compiling and executing C programs, and you’ll be well on your way to becoming a skilled C programmer.

C Programming for Beginners – Chapter 03 : Compilation and Execution in C


Loader Loading...
EAD Logo Taking too long?

Reload Reload document
| Open Open in new tab

Download PDF [666.87 KB]

Applied Machine Learning & Data Science Projects and Coding Recipes for Beginners

A list of FREE programming examples together with eTutorials & eBooks @ SETScholars

95% Discount on “Projects & Recipes, tutorials, ebooks”

Projects and Coding Recipes, eTutorials and eBooks: The best All-in-One resources for Data Analyst, Data Scientist, Machine Learning Engineer and Software Developer

Topics included: Classification, Clustering, Regression, Forecasting, Algorithms, Data Structures, Data Analytics & Data Science, Deep Learning, Machine Learning, Programming Languages and Software Tools & Packages.
(Discount is valid for limited time only)

Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.

Learn by Coding: v-Tutorials on Applied Machine Learning and Data Science for Beginners