The article is written with the view that its readers are able to have a basic knowledge about C programming.
What is a programming language?
A formal language with some basic structure and can perform following operations is called a programming language.
->Takes input i.e. raw data from the user.
->Stores data i.e. saving data and instructions.
->Processes it i.e. performs logical and arithmetic operations.
->Produces output i.e. useful information which is desired by the user.
->Controls the work i.e. the manner and the technique in which all the above operations execute.
-> C Language is a type of structural/procedural programming.
-> C Language works on “top-down” programming approach which means the problem is viewed as a sequence of tasks to be performed.
-> While solving a problem, C Language divides it into segments which behave as subprograms.
The process can be split into four separate stages: Preprocessing, compilation, assembly, and linking.
->Let us have a C program which is saved as “.c” file.
->The first stage of compilation is called preprocessing.
“.c” file goes to preprocessor, which produces “.i” file.
->The second stage of compilation is confusingly enough called compilation.
“.i” file goes to compiler, which produces “.s” file.
->The third stage of compilation is called assembly.
“.s” file goes to assembler, which produces “.o” file, which is in machine language/object type.
->The last stage of compilation is called linking.
“.o” file goes to linker, which produces “.exe” file in windows or “.out” file in Linux.
(The image attached with the article has a diagrammatic representation of this process)
Function of Preprocessor:
->performs “find and replace” operation.
->processes ‘#’ directives.
Function of Compiler:
->checks the grammar of program.
->checks for syntax and errors.
->converts into assembly code.
Function of Assembler:
->converts assembly code to machine language.
Function of Linker:
->links all the files such as printf.o, scanf.o, sio.o, cos.o, etc.
->generates “.exe” file in Windows or “.out” file in Linux.
Let us have a look on the very first code snippet to understand the basic structure of a C code:
include<stdio.h> <—–header file/bin folder
int <—–data type
printf(“Hello, World!”); <—–desired output
return 0; <—–endpoint of the function