About Me

Dr. Ajay Dutta

Introduction to C Programming Language

The skills that supposed to be acquired in this session:

  • Able to understand the brief history of the C language.

  • Able to understand the Benefits of C Language.

  • Able to understand the basic structure of C program.

  • Able to understand the basic program development cycle.

  • Able to be familiar with writing codes, compiling and running a program.

Brief History - language

  • C evolved from two previous languages, BCPL (Basic Combined Programming Language) and B. BCPL was developed in 1967 by Martin Richards as a language for writing operating systems software and compilers.
  • Ken Thompson modeled many features in his language, B, after their counterparts in BCPL and used B to create early versions of UNIX operating system at bell Laboratories in 1970 on a DEC PDP-7 computer.
  • Both BCPL and B were typeless languages, that means the only data type is machine word and access to other kinds of objects is by special operators or function calls.
  • In C, the fundamental data type includes characters (char), integers of several sizes (int) and floating point (float) numbers.
  • The derived data types were created with pointers, arrays, structures, unions, functions and classes.
  • The C language was evolved from B by Dennis Ritchie at Bell Laboratories and was originally implemented on a DEC PDP-11 computer in 1972.
  • It was named C for new language.
  • Initially, C used widely as the development language of the UNIX.  Today, virtually all new major OS are written in C.
  • C is hardware independent, so it is portable to most computers without or with little code modification.
  • The rapid expansion of C over various types of computers led to many variations.  These are similar but incompatible.
  • So, a standard version of C was needed.  In 1983, the X3J11 technical committee was created under the American National Standards Institute (ANSI) Committee on Computer and Information Processing (X3) to provide an unambiguous and machine-independent definition of the language and approved in 1989, called ANSI C.
  • The document is referred to as ANSI/ISO 9899:1990.
  • The more general ANSI then adopted by ISO/IEC, known as ISO/IEC C. Historically, from ISO/IEC, C programming language evolved from C89/C90/C95, C99 and the latest is C11.
  • Because C is a hardware-independent, applications written in C can be run with little or no modifications on a wide range of different computer systems.
  • The C language has formed the basis for many languages including C++, Java, JavaScript, Go, Rust, Limbo, LPC, C#, PHP, Python, Perl, Verilog and C-shell.

Benefits of C

  • As a middle level language, C combines the features of both high level and low level languages. It can be used for low-level programming, such as scripting for drivers and kernels and it also supports functions of high level programming languages, such as scripting for software applications etc.
  • C is a structured programming language which allows a complex program to be broken into simpler programs called functions. It also allows free movement of data across these functions.
  • C language is case-sensitive.
  • C is highly portable and is used for scripting system applications which form a major part of Windows, UNIX and Linux operating system.
  • C is a general purpose programming language and can efficiently work on enterprise applications, games, graphics, and applications.

Basic structure of C program

C  Program Development Life Cycle
  • Computer program is designed to solve problem.  Nowadays it makes ease a lot of our works.
  • The simple steps to find a solution to problems are the same steps used to write a program and basically can be defined as follows:
  1. Define the problem.
  2. Devise a plan to solve it.
  3. Implement the plan.
  4. Test the result to see whether the problem is solved.
  • When creating a program in C.
  1. Determine the objectives of the program.
  2. Decide which method the program will use to solve the problem while preparing the pseudocode or flowchart.
  3. Translate this pseudocode or flowchart into a computer program using the C language.
  4. Run and test the program.
  • Typically, practical steps that might be followed in a simple, small number line of codes for program development are listed below:

Using an editor to enter the source code

From a simple text editor up to complex Integrated/interactive Development Environment (IDE).  Examples:
UNIX:  edexeditemacs and vi.
Window OS:  notepad, Microsoft Visual Studio/.Net®, Borland® C++, Borland Turbo® C++Borland Builder C++BorlandX.

Using a compiler

Computer can’t understand the roman alphabets like English words.  It only can understand machine language, 0’s and 1’s.  The compiler perform this task, yields an object code (such as.obj or .o).

Creating an executable file

C/C++ has function library that contains object code (codes that has been compiled) for predefined functions.  These codes are ready to be used and can be called in the main program such as printf() function.  They perform frequently needed tasks.  Executable program can be run or executed.  Before the executable program is created, a program called linker (to link other object and library files needed by the main program) performs a process called linking.
Running/executing the program
Running the executable file.  If there is no error, that is your program! (a running program or a process).
Debug, debug and debug, finding program bugs, this is in debug mode.
Creating the installation program/package for distribution.

C Program Execution Life Cycle

Normally the C program building process involves four stages and utilizes different ‘tools’ such as a preprocessor, compiler, assembler, and linker.

At the end there should be a single executable file.

  1. Preprocessing is the first pass of any C compilation. It processes include-files, conditional compilation instructions and macros.
  2. Compilation is the second pass. It takes the output of the preprocessor, and the source code, and generates assembler source code.
  3. Assembly is the third stage of compilation. It takes the assembly source code and produces an assembly listing with offsets. The assembler output is stored in an object file.
  4. Linking is the final stage of compilation. It takes one or more object files or libraries as input and combines them to produce a single (usually executable) file. In doing so, it resolves references to external symbols, assigns final addresses to procedures/functions and variables, and revises code and data to reflect new addresses (a process called relocation).


Post a Comment