Why C programming?
Before understanding C programming, it is necessary to understand why C language was created. C is a programming language which made creating software much easier compared to using assembly language.
Why C Programming Language was created?
Computer can understand only zeroes and ones. Writing instructions in binary code is known as machine language. In early days, the programmers used to write programs directly in assembly language which in turn converted instructions to machine language using an Assembler. Later, they felt that writing a program in assembly language was a very time consuming job. So, Programming languages were developed to write code much more easily. Let us know a bit about Assembly Language in order to understand the purpose of a Programming language.
What is Assembly Language
Assembly languages used simple mnemonic instructions to write a program. These instructions are directly mapped to a sequence of machine language operations. For example:
- MOV R1, R2 - moves the data from register R2 to register R1.
- ADD R1, R2 - add the content of register R1 and R2.
- The assembly language was a considerable improvement over machine language.
- This assembly language program is a non-portable one. That is, the program developed for one type of machine does not work on another type of machine. Hence, these programs or code had to written separately for each type of machine
Why Programming Language
In 1950s and 60s, the high-level and low level programming languages were developed. C is considered a low level programming language relative to other high level languages where memory management is automatic. C give you complete control over the memory. For writing the programs, languages use the mechanism like looping construct - to repeatedly execute the instructions you provide, conditional construct - to execute based on a particular condition and so on. It provides proper structure for a program which makes the user/coder/programmer to understand the progress of the instruction flow.
Programming language divides a large program into number of small modules and each module can do the particular operation and finally these modules are combined together to produce the final result. Program written in such language tend to be relatively portable. That means, program written on one machine can be run on most other machines.
We can write the program using either high-level or low level language. This written program is called source code and is not directly executed on the computer. Instead, the written source code needs to be converted into binary code. This is done by the another translating program such as assembler, compiler or interpreter.
This is the program which translates the program written in assembly language into machine code. Computers can execute the machine code without any change.
C Compiler - compiles to a code that can be read by an Assembler
A Compiler translates the source program (written code) into machine specific assembly language code (object code), which is then converted to machine code by an assembler. Compiler can read the complete source code, convert it into the assembly code and produce the error report, if any, to the user. Compiler takes small amount of time for converting source code to object code. C and C++ languages uses a compiler to convert C/C++ language source code (.c or .cpp file) into an executable (.exe) file
C - does not need Interpreter
Interpreter directly executes the code. Input to the interpreter can be a language code like BASIC or LISP. In other cases, it can be bytecode like in Java. In case of language like BASIC, No conversion to machine language is done. Since interpreter directly executes, even syntax errors are thrown at runtime only and then the program stops. In case of Java, a compiler compiles the code and indicates all the errors. Once the programmer/coder/developer fixes the errors, the bytecode is generated in a file with extension .class. In case of C, we do not use an interpreter.