"Testing leads to failure, and failure leads to understanding." - Burt Rutan Visit Now!

Languages

Chapter 0: Intro

Learn C Programming

 Chapter 0: Intro

Chapter 0: Intro

  • C programming is considered as the base for other programming languages, that is why it is known as mother language.
  • The C Language is developed by Dennis Ritchie for creating system applications that directly interact with the hardware devices such as drivers, kernels, etc
  • It can be defined by the following ways:
  1. C as a mother language : C language is considered as the mother language of all the modern programming languages because most of the compilers, JVMs, Kernels, etc. are written in C language, and most of the programming languages follow C syntax, for example, C++, Java, C#, etc.It provides the core concepts like the array, strings, functions, file handling, etc. that are being used in many languages like C++, Java, C#, etc.

  2. C as a procedural language : A procedure is known as a function, method, routine, subroutine, etc. A procedural language specifies a series of steps for the program to solve the problem.A procedural language breaks the program into functions, data structures, etc.C is a procedural language. In C, variables and function prototypes must be declared before being used

  3. C as a structured programming language : A structured programming language is a subset of the procedural language. Structure means to break a program into parts or blocks so that it may be easy to understand.

  • History : History of C language is interesting to know. Here we are going to discuss a brief history of the c language. C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American Telephone & Telegraph), located in the U.S.A. Dennis Ritchie is known as the founder of the c languageIt was developed to overcome the problems of previous languages such as B, BCPL, etc.

Initially, C language was developed to be used in UNIX operating system. It inherits many features of previous languages such as B and BCPL.

Let's see the programming languages that were developed before C language.


LanguageYearDeveloped By
Algol1960International Group
BCPL1967Martin Richard
B1970Ken Thompson
Traditional C1972Dennis Ritchie
K & R C1978Kernighan & Dennis Ritchie
ANSI C1989ANSI Committee
ANSI/ISO C1990ISO Committee
C991999Standardization Committee

  • Features of C Language : 

     C is the widely used language. It provides many features that are given below.

  1. Simple
  2. Machine Independent or Portable
  3. Mid-level programming language
  4. structured programming language (C is a structured programming language in the sense that we can break the program into parts using functions. So, it is easy to understand and modify. Functions also provide code reusability.)
  5. Rich Library (C provides a lot of inbuilt functions that make the development fast.)
  6. Memory Management (provides a lot of inbuilt functions that make the development fast.)
  7. Fast Speed (It supports the feature of dynamic memory allocation. In C language, we can free the allocated memory at any time by calling the free() function.)
  8. Pointers (C provides the feature of pointers. We can directly interact with the memory by using the pointers. We can use pointers for memory, structures, functions, array, etc.)
  9. Recursion (In C, we can call the function within the function. It provides code reusability for every function. Recursion enables us to use the approach of backtracking.)
  10. Extensible (C language is extensible because it can easily adopt new features.)

  • Compilation process in c

What is a compilation?

The compilation is a process of converting the source code into object code. It is done with the help of the compiler. The compiler checks the source code for the syntactical or structural errors, and if the source code is error-free, then it generates the object code.

Compilation process in c

The c compilation process converts the source code taken as input into the object code or machine code. The compilation process can be divided into four steps, i.e., Pre-processing, Compiling, Assembling, and Linking.

The preprocessor takes the source code as an input, and it removes all the comments from the source code. The preprocessor takes the preprocessor directive and interprets it. For example, if <stdio.h>, the directive is available in the program, then the preprocessor interprets the directive and replace this directive with the content of the 'stdio.h' file.

The following are the phases through which our program passes before being transformed into an executable form:

  • Preprocessor (The source code is the code which is written in a text editor and the source code file is given an extension ".c". This source code is first passed to the preprocessor, and then the preprocessor expands this code. After expanding the code, the expanded code is passed to the compiler.)
  • Compiler (The code which is expanded by the preprocessor is passed to the compiler. The compiler converts this code into assembly code. Or we can say that the C compiler converts the pre-processed code into assembly code.)
  • Assembler (The assembly code is converted into object code by using an assembler. The name of the object file generated by the assembler is the same as the source file. The extension of the object file in DOS is '.obj,' and in UNIX, the extension is 'o'. If the name of the source file is 'hello.c', then the name of the object file would be 'hello.obj'.)
  • Linker (Mainly, all the programs written in C use library functions. These library functions are pre-compiled, and the object code of these library files is stored with '.lib' (or '.a') extension. The main working of the linker is to combine the object code of library files with the object code of our program. Sometimes the situation arises when our program refers to the functions defined in other files; then linker plays a very important role in this. It links the object code of these files to our program. Therefore, we conclude that the job of the linker is to link the object code of our program with the object code of the library files and other files. The output of the linker is the executable file. The name of the executable file is the same as the source file but differs only in their extensions. In DOS, the extension of the executable file is '.exe', and in UNIX, the executable file can be named as 'a.out'. For example, if we are using printf() function in a program, then the linker adds its associated code in an output file.)
Let's understand through an example.

hello.c
  1. #include <stdio.h>  
  2. int main()  
  3. {  
  4.     printf("Hello Rookie");  
  5.     return 0;  
  6. }  

Now, we will create a flow diagram of the above program:

Compilation process in c

In the above flow diagram, the following steps are taken to execute a program:
  • Firstly, the input file, i.e., hello.c, is passed to the preprocessor, and the preprocessor converts the source code into expanded source code. The extension of the expanded source code would be hello.i.
  • The expanded source code is passed to the compiler, and the compiler converts this expanded source code into assembly code. The extension of the assembly code would be hello.s.
  • This assembly code is then sent to the assembler, which converts the assembly code into object code.
  • After the creation of an object code, the linker creates the executable file. The loader will then load the executable file for the execution.

Notes Of Chapter : Chapter 0

I'm just a normal average boy with some passion and compassion.....there is nothing to say about me i guess...if you feel to connect with me you can contact me freely...

Post a Comment

© Rookie To Code. All rights reserved. Powered by Mrskt