Wednesday, July 19, 2017

Chapter-1
Introduction of C language
Basic Structure of C Programming
Compilation process
Preprocessor
Header file 

Introduction of C language
C is a computer programming language, procedural, structured, compiled, general-purpose, ANSI certified, high-level programming language that was originally written and developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX Operating System. C is a simple and structure oriented programming language. C programming is inherited from the features of B and BPCL with his own features.
C program is one of the most popular computer languages today because of its structure, high-level abstraction, machine independent feature. C program is also called mother Language of all programming Language. It is the most widely use computer programming language. All other programming languages were derived directly or indirectly from C programming concepts. The file extension of c program is .c.

C programming is called general purpose programming language because it is suitable for designing system software as well as application software. C programming is also called middle (intermediate language) level language because it combines the best features of high level language as well as low level language.

Where we use C Language

C Language is mainly used for;
·         Design Operating system
·         Design Language Compiler
·         Design Database
·         Language Interpreters
·         Utilities
·         Network Drivers
·         Assemblers
History of C language
C language is developed by Mr. Dennis Ritchie in the year 1972 at bell laboratory at USA, C is a simple and structure Oriented Programming Language.
C language has evolved from three different structured languages ALGOL, BCPL and B Language. It uses many concepts from these languages and introduced many new concepts such as data types, struct, and pointer.
In the year 1988 'C' programming language standardized by ANSI (American national standard institute), that version is called ANSI-C. In the year of 2000 'C' programming Language standardized by 'ISO' that version is called C-99

Features and Importance of C:
a)  Highly portable language: - it means C programs written in one computer that can be run on another computer without any modifications.
b)  Structured language: - it has a fixed structure for writing program.
c)   Efficient and fast: - it is efficient and fast due to its verities of data types and powerful operators.
d)  Rich system library: - it has large numbers of keywords, library functions and operators in C’s system library organized in different header files.
e)  Middle Level Language: - C is a middle level language because it combines the best part of high level language with low level language. It is well suited for writing both user and machine oriented programs and provides infinite possibilities.
f)   Extendibility: - C program may contain a number of user defined functions. We can add our own user defined function to the C library if required.

Advantages
a)  It is one of the efficient and fast executing programming languages.
b)  It is easy for debugging, testing and maintaining.
c)   There is no limitation while programming using C. We can develop any kinds of program.
d)  C is powerful language and the use of pointer has made it unique.
e)  Its compiler is easily available.
f)   Length of programs can be reduced by using function.
g)  Reusability of function increases.
h)  It also supports graphics.

Disadvantages
a)  There is no runtime checking.
b)  There is no strict type checking.
c)   It is very difficult to fix the bugs.
d)  It is not powerful like as object oriented programming.
e)  It does not support approach of object oriented programming.
f)   It may be compile time overhead due to the misplacing and excessive use of pointers.
g)  Pointer is one of the unique features which have made C powerful but if it is mishandled the system may crash so it is risky too.

Applications of C

Mainly C Language is used for Develop Desktop application and system software. Some application of C language are given below.
·         C programming language can be used to design the system software like operating system and Compiler.
·         To develop application software like database and spread sheets.
·         For Develop Graphical related application like computer and mobile games.
·         To evaluate any kind of mathematical equation use c language.
·         C programming language can be used to design the compilers.
·         UNIX Kernal is completely developed in C Language.
·         For Creating Compilers of different Languages which can take input from other language and convert it into lower level machine dependent language.
·         C programming language can be used to design Operating System.
·         C programming language can be used to design Network Devices.

Basic structure of C program
   Basic structure of C program is explained below:
Documentation Section
Link Section
Definition Section
Global Declaration Section
Declaration part
Executable part
Main() function section
{



}

Subprogram Section
Function 1 {}
Function 2 {}
-
-
Function n {}




User-defined functions

                                                                                                                                                                                                                                          
Fig. Basic structure of a C programming

·         Documentation section: - it contains a set of comments lines about the name of program, the author, algorithm, methods used and other detail.
For example:
 // WAP to find sum of two number.

·         Link Section: -it provides instruction to the compiler to link functions with program from the system library.
For example:
#include<stdio.h>
#include<conio.h>

·         Definition section: - All symbolic constants are defined in the definition section.
For example:
#define pi 22/7
#define g 9.8

·         Global declaration section: - Variables are declared as globally here which has full scope in the whole program.
For example:
R=7;
Pi=3.147;
·         Main () function section: - Each C program starts and ends with a main () function. It contains declaration and executables parts where declaration part declares all the variables that used in the execution part.
For example:
void main()
{int a=2, b=5;         //declare part
c=a+b;      //executable part

}
·         Subprogram section: -This section contains all the user-defined functions which are called from main() function and ends with main() function.

Complete example of C program

// WAP to calculate the area of circle using function.        // Documentation section

#include<stdio.h>              // link section
#include<conio.h>
#define pi 3.147         // definition section
float r;                        //global declaration section
float area(float x);

void main()                    //starting from here to main function
{  float value;                 //declaration part
clrscr();
printf("Enter a radius of circle\t");
scanf("%f",&r);
value=area(r);          //executable part and also calling user defined function

printf("\nArea of cirlce is: %f",value);
getch();
}

float area(float x)              //user defined function
{
return(pi*x*x);
}


Compiling process

Compilation refers to the processing of creating source code files into object code file. In c programming, compiling process consists of following steps:


a.   Preprocessing: - They instruct compiler to do required pre-processing before actual compilation. You can call this phase text substitution or interpreting special preprocessor directives denoted by #.
b.    Compiler – The compiler translates the high-level instructions file into low-level Assembly language instructions.
c.   Assembling – The assembler converts the Assembly language text instructions into machine code.
d.   Linking –Linking refers to the creation of a single executable file from multiple object files. If these piece of code need some other source file to be linked then linker link them to make it an executable file.
e.   Loader: - It loads the executable code into memory. Program and data stack are created, register get initialized.

Header files and C preprocessor
Header Files:
Header files are a collection of macros, types, functions and constants. Any program that needs those functions can include the corresponding header files.
List of some commonly used Header file and their purposes:

Header Files
Purpose
Functions Declared
stdio.h
Used for standard input and output (I/O) operations.
printf(), scanf(), getchar(), putchar(), gets(), puts(), getc(), putc(), fopen, fclose(), feof()
conio.h
Contains declaration for console I/O functions.
clrscr(), exit(), getch()
ctype.h
Used for character-handling or testing characters.
isupper(), is lower, isalpha()
math.h
Declares mathematical functions and macros.
pow(), squr(), cos(), tan(), sin(), log()
stdlib.h
Used for number conversions, storage allocations.
rand(), srand()
string.h
Used for manipulating strings.
strlen(), strcpy(), strcmp(), strcat(), strlwr(), strupr(), strrev()

C Preprocessor:
The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. C Preprocessor is just a text substitution tool and it instructs the compiler to do require pre-processing before the actual compilation. All preprocessor commands begin with a hash symbol (#) and do not require a semicolon at the end.
Preprocessor directive is a collection of special statement that is executed at the beginning of a compilation process. It is placed in the source program before the main function. There are two types of preprocessor directives:
a.   #define directive: It defines a text substitution, macro substitution and symbolic constant.
Syntax:
#define identifier substitution_token
For Example:
#define TRUE 1
#define FALSE
#define MAX 100
#define PI 3.14

b.   #include directive: This directive searches for a header or source file, which can be processed by the implementation, to be include in the program.
Syntax:
#include <filename>
For example:

#include<stdio.h>

Labels:

0 Comments:

Post a Comment

thank you

Subscribe to Post Comments [Atom]

<< Home