Basic C programming; the Mother Language

c programming language
c programming language

We previously talked about Tower of Hanoi. The basic C programming is developed by Dennis Ritchie for creating system applications that directly interact with the hardware devices such as drivers and kernels etc.

Basic C programming is taken into account because the base for other programming languages, that’s why it’s referred to as mother language.

C Programming Language

  • Mother language
  • System programming language
  • Procedure-oriented programming language
  • Structured programming language
  • Mid-level programming language

C Programming as a mother language

Basic C programming language is taken into account because the mother language of all the fashionable programming languages because most of the compilers such as JVMs and Kernels etc. are written in C language and most of the programming languages follow C syntax, for instance, C++, Java, and C#, etc. And It provides the core concepts just like the array, strings, functions and file handling, etc. And that is getting used in many languages like C++, Java, and C#, etc.

C as a system programming language

A system basic C programming language is employed to make system software. Basic C programming language may be a system programming language because it is often wont to do low-level programming. It is generally wont to create hardware devices such as OS, drivers, and kernels, etc. For example, Linux kernel is written in C and It cannot be used for internet programming like Java, .Net and PHP, etc.

C as a procedural language

A procedure is understood as a function, method, routine and subroutine etc. A procedural language specifies a series of steps for the program to unravel the matter.

A procedural language breaks the program into functions and data structures etc. C is a procedural language. In basic C programming variables and function, prototypes must be declared before being used.

C as a structured programming language

A structured basic C programming language may be a subset of the procedural language. Structure means to interrupt a program into parts or blocks in order that it’s going to be easy to know. In the C language, the programmer breaks the program into parts using functions and It makes the program easier to know and modify.

C as a mid-level programming language

C is taken into account as a middle-level language because it supports the feature of both low-level and high-level languages. Basic C language program is converted into assembly code, it supports pointer arithmetic but it’s machine-independent. A Low-level language is restricted to at least one machine, i.e., machine-dependent. It is machine-dependent and fast to run. But it is not easy to understand. An application-oriented language isn’t specific to at least one machine, i.e., machine-independent even it is easy to understand.

History of C Programming Language

Basic C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American Telephone & Telegraph) located within the U.S.A. Dennis Ritchie is known as the founder of the Basic C programming language. It was developed to beat the issues of previous languages like B and BCPL etc. Initially, the C language was developed to be utilized in UNIX and OS. It inherits many features of previous languages like B and BCPL.

Features of C Language

c programming lifecycle
c programming lifecycle

Features of C Programming

Basic C programming is the widely used language and It provides many features that are given below;

  • Simple
  • Machine Independent or Portable
  • Mid-level programming language
  • Structured programming language
  • Rich Library
  • Memory Management
  • Pointers
  • Recursion
  • Extensible

Simple

C may be a simple language within the sense that it provides a structured approach and to break the matter into parts, the rich set of library functions and data types, etc.

Machine Independent or Portable

Unlike programming language, basic C programs are often executed on different machines with some machine-specific changes.

Mid-level programming language

Although, C is intended to do low-level programming. It is wont to develop system applications like kernel and driver etc. It also supports the features of an application-oriented language. That is why it’s referred to as mid-level language.

Structured programming language

C may be a structured programming language within the sense that we will break the program into parts using functions. Functions also provide code reusability.

Rich Library

C provides tons of inbuilt functions that make the event fast.

Memory Management

It supports the feature of dynamic memory allocation. In C language, the programmer will free the allocated memory at any time by calling the free() function.

Pointers

C provides the feature of pointers. the programmer can directly interact with the memory by using the pointers. We can use pointers for memory, structures, functions, and array, etc.

Recursion

In C, a programmer will call the function within the function. It provides code reusability for every function. Recursion enables us to use the approach of backtracking.

Extensible

C language is extensible because it can easily adopt new features.

First C Program

Before starting the ABCD of C language, the programmer would like to find out the way to write, compile and run the primary C program;

Compilation process in C

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.

The C compilation process converts the source code taken as input into the object code or machine code. The compilation process is often 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
  • Compiler
  • Assembler
  • Linker

Compilation Process in C

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 you can say 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

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.

Compilation process in C

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.

Variables in C

A variable may be the name of the memory location. It is used to store data. Its value is often changed and it is often reused repeatedly. It is how to represent memory location through symbols in order that they are often easily identified.

Types of Variables in C

  • Local variable
  • Global variable
  • Static variable
  • Automatic variable
  • External variable

Local Variable

A programmer must need to initialize the local variable before it’s used.

Global Variable

A variable that’s declared outside the function or block is named a worldwide variable. Any function can change the worth of the worldwide variable. It is available to all the functions.

Static Variable

A variable that’s declared with the static keyword is named static variable.

Automatic Variable

All the variables in C are declared inside the block are the automatic variables by default. but the user can explicitly declare an automatic variable using the auto keyword.

External Variable

The programmer can share a variable in multiple C source files by using an external variable. To declare an external variable, the programmer would like to use an external keyword.

Data Types in C

A data type specifies the sort of knowledge that a variable can store like integer, floating and character, etc.

C Types of Data Types

  • Defined types
  • Derived types
  • Enumeration type
  • Void type

There are the subsequent data types in C language.

C Programming language defined data types are

  • int
  • char
  • float
  • double

Derived data types are

  • array
  • pointer
  • structure
  • union

Enumeration Data Type is an enum

Void Data Type is void

Keywords in C Programming Language

A keyword is a reserved word. You cannot use it as a variable name and constant name etc. There are only 32 reserved words (keywords) within the C language.

Keywords in the c language are

  • auto
  • break
  • case
  • char
  • const
  • continue
  • default
  • do
  • double
  • else
  • enum
  • extern
  • float
  • for
  • goto
  • if
  • int
  • long
  • register
  • return
  • short
  • signed
  • sizeof
  • static
  • struct
  • switch
  • typedef
  • union
  • unsigned
  • void
  • volatile
  • while

C Identifiers

C identifiers represent the name within the C program. For instance variables, functions, arrays, structures, unions, and labels, etc. An identifier is often composed of letters like uppercase, lowercase letters, underscore and digits but the starting letter should be either an alphabet or an underscore. If the identifier isn’t utilized in the external linkage then it’s called as an indoor identifier. If the identifier is used in the external linkage then it is called an external identifier.

Rules for constructing C identifiers

  • The first character of an identifier should be either an alphabet or an underscore and then it can be followed by any of the character, digit or underscore.
  • It should not begin with any numerical digit.
  • In identifiers, both uppercase and lowercase letters are distinct. Therefore, you can say that identifiers are case sensitive.
  • Commas or blank spaces can’t be specified within an identifier.
  • Keywords cannot be represented as an identifier.
  • The length of the identifiers shouldn’t be quite 31 characters.
  • Identifiers should be written in such how that it’s meaningful, short and straightforward to read.

Types of identifiers in C Programming

  • Internal identifier
  • External identifier

Internal Identifier

If the identifier is not used in the external linkage, then it is known as an internal identifier and the internal identifiers can be local variables.

External Identifier

If the identifier is used in the external linkage then it is known as an external identifier. The external identifiers can be function names global variables.

Next, you can read about starting C language as a programmer here.

Imad

I am a Software Engineer with ample experience in making games, websites, mobile apps and augmented reality solutions.

Pin It on Pinterest