1.15 Executing a ' C ' Program.
Executing a ' C ' Program.
Executing a program written in C
involves a series of steps. These are:
- Creating the C program.
- Compiling the C program.
- Linking the C program.
- Executing the C program.
1) Creating the C program: -
- An editor like notepad, WordPad, or Editplus etc. are used to create or write a c program.
- The code which we have written inside the editor is known as source code and should saved with “.c” extension.
2) Compiling the C program: -
- After writing the source code in editor, which is ready for compilation process.
- The source code is compiled by the compilers.
- The compiler converts C source high level code to low level code as assembly source code.
- Then assembler is ready to convert assembly source code to binary code, which code was well understandable by computer machine. i.e. object code.
3) Linking the C program: -
- In this step, the object code of a C program is linked with libraries that are needed for execution of a program.
- The linker is a program which is used to link the program with needed libraries.
- It creates an executable file with “.exe” extension.
4) Executing the C program: -
- Finally, the executable file is run by DOS command prompt or by any other related software.
Process involved in program execution, compilation, interpretation, loading, linking.
In C programming, the execution of a
program involves several important steps:
- writing, compiling, linking, loading, and execution.
- These steps convert human-readable source code into machine-executable instructions.
1) Writing the Program (Source Code
Creation): -
- The programmer writes the C code using a text editor and saves it with a .c extension.
- This file is called the source file, which contains instructions in a high-level language that humans can understand.
2) Compilation: -
- The compiler translates the source code into object code, which is a low-level machine-readable form.
- During this step, syntax errors are checked and reported.
- It creates an object file with a .o or .obj extension.
3) Linking: -
- The linker combines the object file with required libraries (like standard input/output functions).
- If you used printf( ) in your code, the linker ensures that the final executable includes the correct machine code for that function.
- The linker outputs a complete executable file (e.g., program.exe on Windows).
4) Loading: -
- The loader is a program, which is part of the operating system, that loads the executable file into main memory (RAM) before execution.
- It allocates memory for the program's instructions and data, sets up the stack, and prepares the CPU to run the program.
5) Execution: -
- The processor executes the machine code instructions from memory.
- It follows the main( ) function and performs all logic and operations defined in the code.
6) Interpretation: -
- C is a compiled language, not an interpreted one.
- Compilation: Converts the entire program to machine code before execution.
- Interpretation: Executes code line-by-line, translating at runtime (used in languages like Python).
- C programs are not interpreted.