Skip to main content

C programming

Introduction to C:

C is a general-purpose, structured programming language. Its instructions consists of terms that resemble algebraic expression, augmented by certain English keywords such as if, else, for, do and while, etc. C contains additional features that allow it to be used at a lower level, thus bridging the gap between machine language and the more conventional high level language. This flexibility allows C to be used for system programming (e.g. for writing operating systems as well as for applications programming such as for writing a program to solve mathematical equation or for writing a program to bill customers). It also resembles other high level structure programming language such as Pascal and FORTRAN.

2.1 Historical Development of C:
C was an offspring of the ‘Basic Combined Programming Language’ (BCPL) called B, developed in 1960s at Cambridge University. B language was modified by Dennis Ritchie and was implemented at Bell Laboratories in 1972. The new language was named C. Since it was developed along with the UNIX operating system, it is strongly associated with UNIX. This operating system was developed at Bell Laboratories and was coded almost entirely in C.
C was used mainly in academic environments for many years, but eventually with the release of C compiler for commercial use and the increasing popularity of UNIX, it began to gain populuide spread support among compiler professionals. Today, C is running under a number of operating systems including Ms-DOA. C was now standardized by American National Standard Institute. Such type of C was named ANSI C.

2.2 Importance of C:
Now-a-days, the popularity of C is increasing probably due to its many desirable qualities. It is a robust language whose rich set of built-in functions and operators can be used of built-in functions and operators can be used to write any complex program. The C compiler combines the capabilities of an assemble language with the features of a high-level language and therefore it well suited for writing both system software and business packages. In fact, many of the C compilers available in the market are written in C.
Programs written in C are efficient and fast. This is due to its variety of data types and powerful operators. It is many times faster than BASIC (Beginners All Purpose Symbolic Instruction Code – a high level programming language). There are only 32 keywords and its strength lies in its built-in functions. Several standard functions are available which can be used for developing programs. C is highly portable. This means that C programs written for one computer can be seen on another with little or no modification. Portability is important if we plan to use a new computer with a different operating system. C Language is well suited for structure programming thus requiring the user to think of a problem in terms of function modules or blocks. A proper collection of these modules would make a complete program. This modular structure makes program debugging, testing and maintenance.
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 function to the C library. With the availability of a large number of functions, the programming task becomes simple.

2.3 Basic Structure of C programs:

Every C program consists one or more modules called function. One of the function must be called main( ).A function is a sub-routine that may include one or more statements designed to perform a specific task. A C program may contain one or more sections shown in figure:





The documentation section consists of a set of comment lines giving the name of the program, the author and other details which the programmer would like to use later. The link section provides instructions to the compiler to link function from the system library. The definition defines all the symbolic constants. There are some variables that are used in more than one function. Such variables are called global variables and are declared in global declaration section that is outside of all the function. Every C program must have one main( ) function section. This section consists two parts: declaration part and executable part. The declaration part declares all the variables used in the executable part. These two parts must appear between the opening and the closing braces. The program execution begins at the opening braces and ends at the closing brace. The closing brace of the main ( ) function section is the logical end of the program. All the statements in the declaration and executable parts ends with a semicolon. The subprogram section contains all the user-defined functions that are called in the main ( ) function. User-defined functions are generally placed immediately after the main ( ) function, although they may appear in any order. All section, except the main ( ) function section may be absent when they are not required.

2.4 Executing a C Program
Executing a program written in C involves a series of steps:
1. Creating the program;
2. Compiling the program;
3. Linking the program with functions that are needed from the C library; and
4. Executing the program.
The program can be created using any word processing software in non-document mode. The file name should end with the characters “.c” like program .c, lab1.c, etc. Then the command under Ms DOS operating system would load the program stored in the file program .c i.e.
(User-defined Functions)
MSC pay .C
And generate the object code. This code is stored in another file under name ‘program.obj’. In case any language errors are found, the compilation is not completed. The program should then be corrected and compiled again. The linking is done by the command LINK program.obj which generates the executable code with the filename program.exe. Now the command .program would execute the program and give the results.

/* First Program written in C */
/* Save it as hello.c */
# include <stdio.h> /* header file */
Void main ( ) /* main ( ) function */
{
Print (“hello, world in”); /* statement */v
}
Output: hello, world

/* Program to calculate the area of a circle */
/* area.c */
# include <stdio.h> /* library file access */
Void main( ) /* function heading */
{
float radius, area; /* variable decleration */
printf (“Enter radious?=”) /* output statement */
scanf (“%f”, & radius); /* input statement */
area = 3.14159 * radius; /* assignment statement */
printf (“Area=%f”, area); /* output statement */
}

Comments

Popular posts from this blog

Database Management System(DBMS)

Data and Information  Data is an unprocessed raw fact which does  not give complete meaning about any object,person, entity etc. But when various inter-related data arranged in a row, it gives a complete meaning which is referred to as information. For Example: ID Name Address Program 1101 Ram Shrestha Biratnagar BScIT         is information of a specific person. Database Database is a repository(storage) for the organized collection of related information  of data items. It Consist of meaningful arrangement of data, relationship, constraints, schema etc. In modern days we define database as a computerized record-keeping system used to store information and allows users to retrieve and update these information on their request. Some example of databases are telephone directory, data of SLC result, student and employee records etc. Database Management System(DBMS) Database is the softw...

What is Java Applets?

An applet is a special kind of Java program that is designed to be transmitted over the Internet and automatically executed by a Java-compatible web browser. Furthermore, an applet is downloaded on demand, without further interaction with the user. If the user clicks a link that contains an applet, the applet will be automatically downloaded and run in the browser. Applets are intended to be small programs. They are typically used to display data provided by the server, handle user input, or provide simple functions, such as a loan calculator, that execute locally, rather than on the server. In essence, the applet allows some functionality to be moved from the server to the client.

What is manipulator in C++?

Answer: Manipulators are special functions that can be included in the I/O statement to alter the format parameters of a stream. Table-2 shows some important manipulator functions that are frequently used. To access these manipulators, the file < iomanip.h > should be included in program.                               Table-2               Manipulators                                                    Equivalent ios function               set...