Introduction to c



Download 0.91 Mb.
Page1/13
Date28.05.2018
Size0.91 Mb.
#51782
  1   2   3   4   5   6   7   8   9   ...   13




INTRODUCTION TO C

The 'C' language was developed at the AT&T Bell Laboratories, USA by Dennis Ritchie in 1972 on a DEC PDP-II machine. This language is derived from an another language called B developed by Ken Thompson of Bell Laboratories in 1970 which is devCGeloped from the language BCPL (Basic Combined Programming Language) developed by Martin Richard of Cambridge University in 1967 which is derived from the language CPL (Combined Programming Language) developed by Cambridge University and the University of London in 1963 and it is developed from the language called ALGOL (Algorithmic Language) developed by an International Committee in the year 1960.

The 'C' Language was originally developed for programming under UNIX Operating system, which was developed by Ken Thompson and Dennis Ritchie. After developing 'C' almost 90% of UNIX operating system is rewritten in C from assembly language. Therefore UNIX and C have a close relationship.

'C' gives the programmer what he wants, i.e., few restrictions, block structures, standard functions, a compact set of keywords and rich set of data structures.

For many years 'C' has no standard. i.e. Every manufacture developed their style of 'C' compilers. In 1983 the American National Standards Institute (ANSI) established a committee named X3J11 created a standard for the 'C' language. The standard includes the character-set, keywords, compiler environment and the function library etc.

C is a structured language, which uses the compartmentalisation; i.e. A program is broken into different modules, each of which is used for a single specific task. This is supported in 'C' by the use of functions. Basically a 'C' program is a collection of one or more functions.

'C' language also supports the programming structures like sequence, selection and iteration/looping. However the goto statements are not encouraged in structured programming, 'C' supports it too.

Even though 'C' is a high level language it is often called a middle-level language because it combines the elements of high level language, like structured programming, modular programming etc. with the functionalism of the assembly language like direct manipulation of bits, bytes, memory addressees with the help of pointers.

'C' is a flexible, general-purpose language. i.e. The capability of manipulating bits, bytes, memory address makes it well suited for systems programming and the high-level components makes it suitable for application packages. 'C' is used for writing operating systems like UNIX and MS-DOS and the compilers and interpreters for BASIC, FORTRAN, Pascal, LISP, LOGO etc. Popular application packages like dBase, Lotus 1-2-3 and CLIPPER are also written in 'C'.

'C' language is machine independent and it is a highly portable language. Portable means that 'C' programs written for one computer/operating system can be run on another with little or no modification. All high-level languages are portable. 'C' is considered to be highly portable because the machine dependent parts in 'C' compilers are written in 'C'.



Turbo C compiler is an integrated package. It includes an editor, compiler, linker and loader. Every 'C' program file is identified using the ‘.C’ extension. The source code written using the editor is first passed through the C pre-processor. The pre-processor is a program that modifies the source code according to directives supplied in the program. The Pre-processor Directives begin with the # symbol. They must start in the first column and they are usually placed at the beginning of a program. The pre-processor expands the directives and it’s output, the expanded source code is fed to the 'C' compiler. The compiler translates the source code into the assembly language. The system assembler produces the object code (.obj). This object code has to be linked with support routines from the 'C' run-time library to obtain the final executable code (.exe). The systems loader can run the executable code.

'C' Language has no input/output operations. The compiler compiles a language of functions, all input and output is done with functions. Because of this feature, a standard library gives 'C' its most endearing feature is portability.

Every function must be defined before it can be used in the program. Every function definition has two parts, a function header and a body that follows it. The header defines the function’s name and the arguments. The headers of the library functions are stored in header files with extension .h. So these must be included before the library functions are used in a 'C' program.

Using the Turbo C Compiler

Type tc at the DOS prompt and press ENTER key. The Turbo C integrated environment displays on the screen. You can use the menu options like save, open, create a new file etc. from the main menu strip which is at the top most line of the screen.

After typing the program you can save it by pressing the F2 key or FileSave command. If necessary give the filename. To execute the program press Ctrl+F9 key combination. The progress window on the screen will show each phase in the creation of the executable file. If there are no errors, the screen will be cleared and the program will start running. After the program is executed, you will get back to the Turbo C environment automatically. You can view the user screen by pressing the Alt+F5 key combination. To return to the Turbo C environment strike any key.

If there are any errors in the program, the messages along with the line numbers will be displayed in a separate message window at the bottom of the screen. Pressing the F6 key can make corrections, which place the cursor in the Edit window. After making corrections save it again and run.

You can activate the main menu by pressing the F10 key and then use the arrow keys. You can quit the Turbo C integrated environment by pressing Alt+X key combination.

Programming Conventions

‘C’ is a freestyle language i.e., no restriction on program writing. Statements can start and end at any column. You can include spaces, tabs and blank lines in a program to improve readability.

A ‘C’ statement is called an expression statement, which is terminated by a semicolon. They are not restricted to one line, can extend to many lines and multiple statements separated by semicolons can be written in a single line. ‘C’ is a case-sensitive language. The programs are written in lower case, with some words capitalised.

‘C’ language implements the concept of structured programming through code blocks. A code block is a logically connected group of program statements that is treated as a unit. A code block is created by placing the sequence of statements between curly brackets ({and}) called braces.

A ‘C’ program consists of one or more functions and one of they must be called main(). The main() is the first function executed in the program, but not necessarily the first function. The statements of a function are enclosed in a code block may contain additional nested blocks and each block keeps their variables as local.

Header files with extension .h can be included using the include statement.

e.g.:- # include

The header filename should be enclosed within angle brackets (< and >).




Download 0.91 Mb.

Share with your friends:
  1   2   3   4   5   6   7   8   9   ...   13




The database is protected by copyright ©ininet.org 2024
send message

    Main page