INTRODUCTION TO ‘C'

‘C’ is a structured, high-level, machine independent language. The early version of ‘C’ developed during 1970s is known as ‘Traditional C’. Then, in the year 1989, ‘ANSI C’ was introduced to meet the standards set by the American National Standards Institute (ANSI) to become a standard structured programming language. ANSI C was approved by the International Standards Organization (ISO) in 1990 and was called as ANSI/ISO C.
Evolution of C
The evolution of C started with the Common Programming Language (CPL) during the early 1960. In 1967, Martin Richards modified CPL into a type-less language named Basic Combined Programming Language (BCPL). BCPL allowed its users to have direct access to the memory. This made it useful to system programmers.
In 1970, Ken Thompson at Bell Labs, USA, wrote his own variant of BCPL that makes use of various concepts already implemented in BCPL and called it ‘B’ language. The language - B was used as a language for creating the early versions of UNIX OS. Later, the designers of UNIX modified the language - B with various features and named it C. But, Dennis Ritchie at Bell Laboratories, was given the credit for designing C in 1972. Subsequently, UNIX OS was rewritten entirely in C.
Standardization of C Language
During the 1970s, the C Programming language became increasingly popular. Many universities and organizations began creating their own variations of the language for their own projects. During the late 1970s and early 1980s, various versions of C were implemented for a wide variety of mainframe computers, mini computers and micro computers, including the IBM PC.
During this time, a need was realized to standardize the definition of the C language. In 1983, the American National Standards Institute (ANSI) formed a committee to establish a standard specification of C known as "ANSI C". This work resulted in a standardized version of C, called ANSI C, having acceptance internationally. Part of ANSI C was a set of software libraries called the ANSI C standard library.
Characteristics of C
‘C’ language became very popular because of its special features as listed below:
- It provides a rich set of built-in-functions and operators using which complex programs can be easily written.
- It combines the capabilities of an assembly language with the features of a high-level language. Therefore it is well suited for writing both system software and application packages.
- It has got a variety of data types for efficient storage and operation.
- It is highly portable. That means the programs written in C for one computer can run on another with little or no modification.
- It promotes modularity in writing software by allowing the programs to be written as modules or sub programs. The name given for a sub program is ‘Function’.
Structure of ‘C’ Program
The general basic structure of C program is shown in the figure below. The whole program is controlled within main ( ) along with left brace denoted by “{” and right braces denoted by “}”. The local variable declarations and executable program structures are enclosed within “{” and “}”, and is called the body of the main function. The main ( ) function can be preceded by documentation, preprocessor statements and global declarations.
Documentations
The documentation section consist of a set of comment lines giving the name of the program, the another name and other details, which the programmer would like to use later.
Preprocessor Statements
The preprocessor statements begin with # symbol and are also called as preprocessor directive. These statements instruct the compiler to include C preprocessors such as header files and symbolic constants before compiling the C program. Some of the preprocessor statements are listed below.
Global Declarations
The variables are declared before the main ( ) function as well as user defined functions are called global variables. These global variables can be accessed by all the user defined functions including main ( ) function.
Structure Of a C Program - Presentation:
The main ( ) function
Each and Every C program should contain only one main ( ). The C program execution starts with main ( ) function. No C program is executed without the main function. The main ( ) function should be written in small (lowercase) letters and it should not be terminated by semicolon. Main ( ) executes user defined program statements, library functions and user defined functions and all these statements should be enclosed within left and right braces.
Braces
Every C program should have a pair of curly braces ({, }). The left brace indicates the beginning of the main ( ) function and the right braces indicates the end of the main ( ) function. These braces can also be used to indicate the user-defined functions beginning and ending. These two braces can also be used in compound statements.
Local Declarations
The variable declaration is a part of C program and all the variables are used in main ( ) function should be declared in the local declaration section is called local variables. Not only variables, we can also declare arrays, functions, pointers etc. These variables can also be initialized with basic data types. For example:
main()
{
int sum = 0;
int x;
float y;
}
Here, the variable sum is declared as integer variable and it is initialized to zero. Other variables declared as int and float and these variables inside any function are called local variables.
Program statements
These statements are building blocks of a program. They represent instructions to the computer to perform a specific task (operations). An instruction may contain an input-output statements, arithmetic statements, control statements, simple assignment statements and any other statements and it also includes comments that are enclosed within /* and */ . The comment statements are not compiled and executed and each executable statement should be terminated with semicolon.
User defined functions
These are subprograms, generally, a subprogram is a function and these functions are written by the user are called user ; defined functions. These functions are performed by user specific tasks and this also contains set of program statements. They may be written before or after a main () function and called within main () function. This is an optional to the programmer. Now, let us write a small program to display some message shown below:
#include <stdio.h>
main()
{
Printf(“Welcome to the world of C\n”);
}