As a programming language, c is rather like Pascal or FORTRAN. Values are stored in variables. Programs are structured by defining and calling functions. Program flow is controlled using loops if statements and functions. input and output can be directed to the terminal or to files. related data can be stored together in arrays or structures.
Of the three languages, C allows the most precise control of input and output. C is also rather terser than Fortran or Pascal. this can result in short efficient programs, where the programmer has made wise use of C’s range of powerful operators. it also allows the programmer to produce programs which are impossible to understand.
programmers who are familiar with the use of pointers (or indirect addressing, to use the correct term) will welcome the ease of use compared with some other languages. undisciplined use of pointers can lead to errors which are very hard to trace. this course only deals with the simplest applications of pointers.
It is hoped that newcomers will find C a useful and friendly language. Care must be taken in using C. Many of the extra facilities which it offers can lead to extra types of a programming error. You will have to learn to deal with these to successfully make the transition to being a C programmer.
A brief introduction on the origin
C is a middle level and case sensitive general-purpose programming language, which has been closely associated with the UNIX operating system for which it was developed – since the system and most of the program that runs it are written in C.
Many of the important ideas of C came from the language BCPL, developed by Martin Richards. The influence of BCPL on C proceeded indirectly through the language B, which was written by Ken Thompson in 1970 at Bell Labs, for the first UNIX system on a DEC PDP-7. BCPL and B are “typeless” languages whereas C provides a variety of data types. In 1972 Dennis Ritchie at Bell Labs writes C and in 1978 the publication of “The C programming language” by Brian Kernighan & Dennis Ritchie caused a revolution in the computing world.
In 1983, the American National Standards Institute (ANSI) established a committee to provide a modern, comprehensive definition of C. The resulting definition, the ANSI standard, or “ANSI C”, was completed in 1988.
C for personal computers
With regards to personal computers, Microsoft C for IBM (or clones) PC’s, Borland C and Borland’s Turbo C are seen to be the two most commonly used systems. This course teaches C under Microsoft’s Windows and Disk operating system.
C program will look similar under any other systems (such as VMS or DOS), some other features will differ from system to system. In particular, the method of compiling a program to produce a file of runnable code will be different on each system. The UNIX system is itself written in C., in fact, C was invented specifically to implement UNIX. All of the UNIX commands which you type, plus the other system facilitates such as password checking, line printer queues or magnetic tape controllers are written in C.
In the course of the development of UNIX, hundreds of functions were written to give access to various facts of the system. These functions are available to the programmer in libraries. By writing in C and using the UNIX system libraries, very powerful system programs can be created. These libraries are less easy to access using other programming languages. C is, therefore, the natural language for writing UNIX system program.
Program development and execution method
Developing a program in a compiled language such as C requires at least four basic steps. The basic principle is that whatever C compiler you choose to use, the steps are nearly always the same. Here, in this tutorial, all the programs are written based on the Borland C compiler. The basic steps are.
- Editing or writing the program
- Compiling it
- Linking it
- Executing it
About the IDE
Borland C IDE (Integrated Development Environment) is a powerful environment, which allows us to create and execute a C program. The IDE is completely menu-driven and allows the user to create, edit, compile and run C programs using easy-to-easy menus or by combined keystrokes.
to write a new program first open a new file from the File menu. Here, type the program directly in the new window on the screen and save the resulting text as a separate file. This is often referred to as the source file. The custom is that the source file of a C program is stored with the extension .c for C programming language.
We can’t directly execute the source file. To run on any computer system, the source file must be translated into binary numbers understandable to the computer’s Central processing unit (for example, the Pentium microprocessor). This process produces an intermediate object file with the extension .obj, which stands for Object. We compile a C source file either through the menu as Project > compile or through combined keystrokes as Alt+F9.
The first question that comes to most people’s mind is “why is linking necessary?” The main reason is that many compiled languages come with library routines that can be added to your program. These routines are written by the manufacturer of the compiler to perform a variety of tasks, from input-output to complicated mathematical functions. In the case of C, the standard input and output functions are contained in a library file (stdio.h) so even the most basic program will require a library function. After linking, the file extension is .exe, which is an executable file. We can both link and execute a compiled C program at the same time either through the menu as Debug>Run or through combined keystroke as Ctrl+F9.
Now, we can run the .exe file as we run other applications, simply by typing their names at the DOS prompt or run using windows menu.