Unit - 1
Unit - 1
C Language
C is a programming language which born at “AT & T’s Bell Laboratories” of USA in 1972. It was
written by Dennis Ritchie. This language was created for a specific purpose: to design the UNIX
operating system. American National Standards Institute (ANSI) formed a committee in 1983 to
establish a standard definition of C. This committee approved a version of C in 1989 which is
known as ANSI C.
Importance of C :
Now a day, there are many high level languages like Pascal, Basic, & Java. But C is a robust
language whose rich set of built in functions & operators can be used to write any complex logic
program. The C language compiler combines the capabilities of a low level language with the
features of high level language. Therefore the language is suitable for writing both system
software as well as business packages & other software.
1. Program written in C are very efficient & fast for the programmer & developer. This is due to its
variety of data types & powerful operators. It is many time faster than other languages. This
helps developers in saving their valuable time.
2. C is powerful & flexible language which helps system developers & programmers to deliver
various complex tasks with ease. C is used for diverse project as operating systems, word
processors, graphics, spreadsheets & even compilers for other languages.
3. C is popular among professional programmers for programming, as a result wide variety of C
compilers & helpful accessories are available.
4. There are only 32 keywords; several standard functions are available which can be used for
developing program.
5. C is highly portable language. This means that a C program written for one computer system can
be run on another system with little or no modification. Portability is enhanced by the ANSI
standard for C, the set of rules for C compilers.
6. Another feature is its ability to extend itself. A C program is basically a collection of various built-
in functions supported by C library. We can also add our own functions to the C library. These
functions can be reused in other applications or programs by passing pieces of information to the
functions, you can create useful, reusable code.
7. Writing program with user-defined functions makes program more simple & easy to understand.
Breaking a problem in terms of functions makes program debugging, maintenance & testing
easier.
Introduction of C Editor
An editor is a one type of software tools in which user can type the text, modifying deleting and
formatting an existing text. To type your C program you need another program called editor.
Once the program has been typed it needs to be converted to machine language (0s and 1s)
before the machine can execute it. To carry out this conversion we need another program called
Compiler.
For example: Notepad, Wordpad, C editor Turbo C, Turbo C++, Dos Editor, JAVA, FoxPro etc.
For writing a C program, generally we are using TC (Turbo Compiler) editor and executing a C
program.
Here, some of the important shortcut keys are listed below for working with TC.
No. Shortcut Use
1 F2 Save Program file (Save C program with C extension)
2 F3 Open an existing save program file.
3 F5 To maximize editor area.
4 Alt + Back Space Undo last changes in editor.
5 Shift + Alt + Back Space Redo last changes by Undo.
6 Ctrl + Insert key Copy selected Text from Editor.
7 Shift + Del Cut selected Text from Editor.
8 Shift + Insert key Paste Copied or Cut text.
9 Ctrl + Del Clear selected Text.
10 Alt + F9 Compile C Program.
11 Ctrl + F9 Run C Program.
12 F7 or F8 Step by Step debugging.
Now assuming that, you are using a Turbo C or Turbo C++ compiler here are the steps that you
need to follow to compile and execute your first C program...
(a) Start the compiler at C> prompt. The compiler (TC.EXE is usually present in C:\TC\BIN directory)
(b) Select New from the File menu.
(c) Type the program.
(d) Save the program using F2 under a proper name (say program 1.c).
(e) Use Ctrl + F9 to compile and execute the program.
(f) Use Alt + F5 to view the output.
Now, that on compiling the program its machine language equivalent is stored as an EXE file
(Program1.EXE) on the disk. This file is called an executable file. If we copy this file to another
machine we can execute it there without being required to recompile it. In fact the other
machine need not even have a compiler to be able to execute the file.
A word of caution! If you run this program in Turbo C++ compiler, you may get an error – “The
function printf should have a prototype”. To get rid of this error, perform the following steps and
then recompile the program.
(a) Select ‘Options’ menu and then select ‘Compiler’ |C++ Options. In the dialog box that pops
up, select ‘CPP always in the ‘Use C++ Compiler’ options.
(b) Again select ‘Options’ menu and then select ‘Environment | Editor’. Make sure that the
default extension is ‘C’ rather than ‘CPP’.