Introduction to C
C Language is a powerful programming language developed by Dennis Ritchie at Bell Laboratories in 1970. C Language is a general purpose high-level language.
Most of its principles and ideas were taken from the earlier language B, BCPL and CPL. CPL (Common Programming Language) was developed jointly between the Mathematical Laboratory at the University of Cambridge and the University of London Computer Unit in 1960s.CPL was too large for use in many applications. In 1967, BCPL (Basic Combined Programming Language) was created as a scaled down version of CPL retaining its basic features by Martin Richards. Ken Thompson at Bell Labs, USA wrote his own variants of BCPL and called it B. In due course, the designers of UNIX modified it to produce a programming language called C. In 1970, a co-worker of Ken Thompson, Dennis Ritchie developed C Language by taking some of the generality found in BCPL and the B language into a more powerful language called C. Ninety percent of the code of the UNIX operating system and of its descendants is written in C. The name C comes being the successor of B and BCPLIn 1983, an ANSI standard for C emerged consolidating its international acceptance.
Features of C
C is powerful: The increasing popularity of C is due to its many desirable qualities. It is a robust language whose rich set of built-in functions and operators can be used to write any complex program. The C compiler combines the capabilities of an assembly language with features of a high-level language and therefore it is well suited for writing both System programs and Application programs.
C is a small language: It has only 32 keywords and its strength lies in its built-in functions and is easy to learn.
C is a structured programming language: language is well suited for structured programming, thus requiring the user to think of a problem in terms of function modules or blocks.
C is quick: A well written C program is likely to be as quick as or quicker than a well-written program in any other high-level language.
C is a core language: A number of common and popular programming languages like C++, Java, Perl, PHP etc are based on C. Having learnt C, it will be much easier to learn languages that are largely or in part based upon C.
C is stable: The ANSI standard for C was created in 1983. The language has not been undergone much changes then. The latest standard is C99 with only minor changes over ANSI C.
C is extendable: Another important feature of C is its ability to extend itself. A C program is basically a collection of functions that are supported by the C library. We can continuously add our own functions to the C library.
Compiling and Running C programs
A high-level source program must be translated first into a form the machine can understand. This is done by software called the Compiler. The compiler takes the source code as input and produces the machine language code for the machine on which it is to be executed as output.
Compiling and executing a C program requires you to work with four kinds of files:
1. Regular source code files. These files contain function definitions, and have names which end in ".c" by convention.
2. Header files. These files contain function declarations (also known as function prototypes) and various preprocessor statements. They are used to allow source code files to access externally-defined functions. Header files end in ".h" by convention.
3. Object files. These files are produced as the output of the compiler. They consist of function definitions in binary form, but they are not executable by themselves. Object files end in ".obj” in some operating systems (e.g. Windows, MS-DOS),
4. Binary executables. These are produced as the output of a program called a "linker". The linker links together a number of object files to produce a binary file which can be directly executed. They generally end in ".exe" on Windows.
C Program
C Program can be considered as collection of functions. A function is a sub program that contains instructions or statements to perform a specific computation. It is easy to define the functions and use it in C.A C program may contain several functions one of which must be main (). This function is the starting point of the program. Other functions are called from main. After executing the statements in a function the program control will be returned to the calling function. The function may be a user defined function or a built in library function.
The main components of a C program are
Preprocessor directives
Global Variables
User defined functions
Main function
The general syntax of a function is
returnvalue functioname(arguments)
{
variable decalarations
executable statements
}
Eg: void bio(void)
{
printf(“Neethu\n”);
printf(“CEK”);
}
void main(void) /* program execution begins here */
{
clrscr(); /* calling a built in function to clear the screen */
bio();/* calling the bio function to print the name and college */
}
Output of the above program is:
Neethu
CEK
The use of functions in C serves many advantages:
1. It facilitates top-down modular programming. In this programming style, the high level of the overall problem is solved first while the details of each lower-level function are addressed later.
2. The length of a source program can be reduced by using functions at appropriate places.
3. It is easy to locate and isolate a faulty function for further investigations.
4. A function may be used by many other programs. This means that a C programmer can build on what others have already done, instead of starting from scratch.
C Language is a powerful programming language developed by Dennis Ritchie at Bell Laboratories in 1970. C Language is a general purpose high-level language.
Most of its principles and ideas were taken from the earlier language B, BCPL and CPL. CPL (Common Programming Language) was developed jointly between the Mathematical Laboratory at the University of Cambridge and the University of London Computer Unit in 1960s.CPL was too large for use in many applications. In 1967, BCPL (Basic Combined Programming Language) was created as a scaled down version of CPL retaining its basic features by Martin Richards. Ken Thompson at Bell Labs, USA wrote his own variants of BCPL and called it B. In due course, the designers of UNIX modified it to produce a programming language called C. In 1970, a co-worker of Ken Thompson, Dennis Ritchie developed C Language by taking some of the generality found in BCPL and the B language into a more powerful language called C. Ninety percent of the code of the UNIX operating system and of its descendants is written in C. The name C comes being the successor of B and BCPLIn 1983, an ANSI standard for C emerged consolidating its international acceptance.
Features of C
C is powerful: The increasing popularity of C is due to its many desirable qualities. It is a robust language whose rich set of built-in functions and operators can be used to write any complex program. The C compiler combines the capabilities of an assembly language with features of a high-level language and therefore it is well suited for writing both System programs and Application programs.
C is a small language: It has only 32 keywords and its strength lies in its built-in functions and is easy to learn.
C is a structured programming language: language is well suited for structured programming, thus requiring the user to think of a problem in terms of function modules or blocks.
C is quick: A well written C program is likely to be as quick as or quicker than a well-written program in any other high-level language.
C is a core language: A number of common and popular programming languages like C++, Java, Perl, PHP etc are based on C. Having learnt C, it will be much easier to learn languages that are largely or in part based upon C.
C is stable: The ANSI standard for C was created in 1983. The language has not been undergone much changes then. The latest standard is C99 with only minor changes over ANSI C.
C is extendable: Another important feature of C is its ability to extend itself. A C program is basically a collection of functions that are supported by the C library. We can continuously add our own functions to the C library.
Compiling and Running C programs
A high-level source program must be translated first into a form the machine can understand. This is done by software called the Compiler. The compiler takes the source code as input and produces the machine language code for the machine on which it is to be executed as output.
Compiling and executing a C program requires you to work with four kinds of files:
1. Regular source code files. These files contain function definitions, and have names which end in ".c" by convention.
2. Header files. These files contain function declarations (also known as function prototypes) and various preprocessor statements. They are used to allow source code files to access externally-defined functions. Header files end in ".h" by convention.
3. Object files. These files are produced as the output of the compiler. They consist of function definitions in binary form, but they are not executable by themselves. Object files end in ".obj” in some operating systems (e.g. Windows, MS-DOS),
4. Binary executables. These are produced as the output of a program called a "linker". The linker links together a number of object files to produce a binary file which can be directly executed. They generally end in ".exe" on Windows.
C Program
C Program can be considered as collection of functions. A function is a sub program that contains instructions or statements to perform a specific computation. It is easy to define the functions and use it in C.A C program may contain several functions one of which must be main (). This function is the starting point of the program. Other functions are called from main. After executing the statements in a function the program control will be returned to the calling function. The function may be a user defined function or a built in library function.
The main components of a C program are
Preprocessor directives
Global Variables
User defined functions
Main function
The general syntax of a function is
returnvalue functioname(arguments)
{
variable decalarations
executable statements
}
Eg: void bio(void)
{
printf(“Neethu\n”);
printf(“CEK”);
}
void main(void) /* program execution begins here */
{
clrscr(); /* calling a built in function to clear the screen */
bio();/* calling the bio function to print the name and college */
}
Output of the above program is:
Neethu
CEK
The use of functions in C serves many advantages:
1. It facilitates top-down modular programming. In this programming style, the high level of the overall problem is solved first while the details of each lower-level function are addressed later.
2. The length of a source program can be reduced by using functions at appropriate places.
3. It is easy to locate and isolate a faulty function for further investigations.
4. A function may be used by many other programs. This means that a C programmer can build on what others have already done, instead of starting from scratch.
Comments
Post a Comment