We have gone through the basic introduction part of C language in the previous article.
Now, we will be learning about writing C programs, compiling, and running the same to see the desired output. This will mark the beginning of C Programming hands-on.
Integrated Development Environment (IDE)
Integrated development environments or IDE are the platforms to write and compile our C programs.
Tools for software development with C are provided by IDE.
Some famous IDEs for the C language are Visual studio, Eclipse, Code::Blocks, Dev C++, etc.
An IDE consists of a text editor and a compiler.
The text editor is where we are supposed to write our C program.
The source file is the file containing our C program. In the C language, the source file is saved with a .c extension.
C compiler: We need to compile the code written in the source file with the help of the compiler to get the error if present otherwise output is shown.
Let’s understand how this compilation takes place.
What is compiling
The program written in C is in a high-level language which computers/machines don’t understand.
It needs to be converted to machine language or low-level language (which is a binary language consisting 0 and 1) so that computers can understand and execute it. This conversion is called compiling a program and is done by the compiler.
The compiler scans the entire program and translates it as a whole into machine code.
Compilers are used by programming languages such as C, C++, Java, etc.
Interpreters are used by programming languages such as Python, Java Script to perform the job of compiling and running the program as the compiler does.
After writing and compiling a C program it is important to understand the program’s execution.
Execution of a program
Processor, RAM, and hard disk are the important hardware in our computer responsible for executing a program.
A file with the ‘.exe’ extension is software. When a programmer is supposed to make software for clients, the software is nothing but a .exe file.
How to run/execute software or file
To run a .exe file, the user should save the file on a hard disk. By double-clicking on the same, a copy of it will load in RAM. Every program gets executed only after loading in RAM. Now the OS will allocate memory to our program, i.e. memory management. Once the memory is allocated, the output window automatically the execution process will begin.
The program contains many instructions. One by one, every instruction reaches the processor. In the processor, we have:
MU: It is the memory unit that contains a set of registers. The instruction gets stored in one of the registers known as the instruction register.
CU: It is a circuit that will read the instructions, decode them, and give the signal to ALU to perform operations on it.
ALU: This is responsible for all arithmetic and logical calculations. In this way, the very first instruction gets executed.
Similarly, every instruction gets executed by the same process, and finally, the program ends.
How to write and compile c program on windows
Though there are several IDEs available for writing and compiling C programs for windows, programmers use all of them according to their needs and comfort.
There are no such restrictions to use a particular one.
Here we are talking about Dev C++which allows us to write, compile, and run our program.
Make sure that it is installed on your computer and must be in ready-to-use condition.
Follow the steps below to write the program in Dev C++.
- Open Dev C++ on your PC. On opening, you will get a window.
- Click on the file option on the top left side of the window. And then click on new.
- Choose a source file, and you will get a text editor to write the program.
- Write down the desired code in the source file.
- Once done with the code, click on the ‘execute’ option and choose to compile and run.
- Save the file at desired location with the .c extension.
- Once the file is saved, automatically, then the output window shows the result: “C language”.