C Program Execution Flow

 

 

Every programming language follows a specific set of steps for executing a program, involving various stages that occur between writing the code and its actual execution. While the overall process is generally similar, there are slight variations depending on the programming language being used and the compiler/interpreter involved. C is a compiler-based language that offers numerous outstanding features. As a programming language, C has applications across various domains.

In this discussion, we will explore the C programming language execution and its step-by-step process of executing a program, starting from writing the source code to obtaining the output. Before delving into the detailed explanation of each step, it would be beneficial to have a general understanding of the execution flow. To provide a visual representation of this flow, we have included a flowchart below.

C-Programming-Code-Execution-Flow-Chart

Figure: C Program Execution Flow


Here is a detailed explanation of all the steps shown in the image above:

Step 1: Editing

  • The first step is to create and edit the program.
  • Write the C program using a text editor, such as VS Code, Notepad++, Sublime or Notepad.
  • Save the program with the [.C] extension.
  • The file saved with the [.C] extension is known as the “Source Program.”

Step 2: Compiling

  • Compiling the C Program: Provide the C source code file with the [.C] extension as input to the compiler.
  • The compiler converts the source code into equivalent machine instructions.
  • The compiler checks for errors in the source code.
  • If the source code is error-free, the code is converted into an object file with the [.Obj] extension.

Step 3: Checking Errors

  • The compiler checks for errors during the compilation process.
  • If any errors are found, the compiler reports them to the user.
  • The user needs to make edits to the program based on the reported errors.
  • After making the edits, the compiler re-checks the program for any remaining errors.
  • If the program is error-free, it proceeds to link with the necessary libraries.

Step 4: Linking Libraries

  • The program is linked with the header files that were included.
  • It is also linked with other required libraries.
  • The linker is responsible for performing this linking process.

Step 5: Error Checking

  • If any runtime errors occur during program execution, they are reported as “run-time” errors.
  • The programmer needs to review the code and find a solution to fix these errors.

Leave a comment