Understanding Execution of Programs

Before we start writing actual codes in C, lets first try to understand how programs are compiled and executed in the computer. The computer does not understand the English language in which we write the code. All the computer can understand is combinations of 0's and 1's that we call binary code. So for our program to be executed by the computer we first need to somehow convert the source code that we wrote into binary code. That is the job of the compiler.

The compiler is a software that takes our source code as input and generates the binary code as output for the computer to understand and execute. The compiler checks the source code line by line for spelling and syntactical errors. For example if we wrote prinf instead of printf, or we missed a ";" or a "(" somwehere, the compiler will show an error and instruct us to correct those errors.

Next comes the linker. The compiler first converts the surce code into an intermediate code( the object code with a .o file extension ). After that the linker links this object code to other object codes that might be needed in our program. after all the linking is done, the object code is converted to the binary code.

Then there is the loader. The job of the loader is to load the binary code into the main memory for execution. It also loads any resources like files or variables that are required by the program.

Thus we can divide the writing execution of programs into 5 steps as shown below:

Facebook Google+ Twitter WhatsApp