How does C Programming Language Work

Categories: C Programming language C language

How does C Programming Language Work?

 

Execution of the C program involves 5 steps. These are:

  1. Creating the Program
  2. Preprocessing
  3. Compiling the Program
  4. Linking the Program with functions from the C library
  5. Executing the Program

 

  1. Creating the Program: Firstly, we need to create a C program. For that, we will open a text editor and write our C program into it. Then save the file with .c extension. For example: hello.c The program written into the file is known as the source code, and it serves the original form of the C program.

 

  1. Preprocessing: Preprocessing is the stage where source code is passed for the first time. This stage consists of the following steps:

 

  1. Expansion of Macros and Comment Removal
  2. Expansion of the included files
  3. Conditional compilation The preprocessed output of hello.c is stored in the file hello.i.
  4. Compiling the Program: Once our source code is preprocessed in the file hello.i. Now our file is ready for compilation, which after compilation produces an intermediate compiled output file hello.s, which is in assembly level instructions. During the compilation process, the compiler checks for all the compilation errors. If the C compiler gives no error, then the hello.s is taken as input and turned into hello.o by the assembler in the next phase. This file contains machine-level instructions. At this phase, only existing code is converted into machine language, and the function calls are not resolved. Since the object file is not executable, the process is transferred to the linker, which ultimately produces a .exe file.

 

  1. Linking the Program with functions from the C library: This is the final phase, in which all of the function calls are linked to their definitions. Linker knows where all these functions are implemented.   The linker performs additional work and adds more code to our programme that is required when it starts and stops. Setting up the environment, for example, requires a code, as does sending command-line inputs. The linker connects the object code of our programme file to the C library functions, resulting in an.exe file, hello.exe, which is an executable file, will be created here.

 

  1. Executing the Program: The execution of a program is a very simple task. After giving the command to execute a particular program. The loader will load the executable object code into the RAM and execute the instructions.

Top Blogs
C Functions ! What is a Function Published at:- Types of Function in C ! Library Function in C ! User Defined Function In C ! Function Definition Published at:- Functions that return multiple values -C Example Published at:- Functions with arguments and return values -C Examples Published at:- Functions with arguments and no return values. Published at:- Example of Function with no return type and no argument Published at:- Loops in C Published at:- Structure in C: Introduction Published at:- C Memory Management ! Dynamic memory allocation Published at:- Learn C Programming language with example Published at:- C Interview Questions And Answers Published at:- What values are printed when we run following? Published at:- C Program example: Input a number and print sum of its digits Published at:- Pointer declaration in C ,Address operator Published at:- C Language Interview Question and Answers Published at:- Benefits of C language over other programming languages Published at:- History of C Language : Introduction to C Programming Language Published at:- How does C Programming Language Work Published at:- Importance of C Programming Language Published at:- Input and Output Functions in C Published at:- Introduction to Implementation of Queue using Linked List Published at:- First C Program Published at:- Inception Of C Language Tutorial for Beginners Published at:- The C Compiler work in C language and its important Published at:- Program Structure with “Hello World” Example Published at:- C Programming Interview Questions Set 1 Published at:- C Programming Interview Questions Set 2 Published at:- C Programming Interview Questions Set 3 Published at:- C Programming Interview Questions Set 4 Published at:- C Programming Interview Questions Set 5 Published at:- C Programming Interview Questions Set 6 Published at:- C Programming Interview Questions Set 7 Published at:- C Programming Interview Questions Set 8 Published at:- C Programming Interview Questions Set 9 Published at:-
R4R.co.in Team
The content on R4R is created by expert teams.