C Program Basics
C - INTRODUCTION
C is a general - purpose, structured programming language, developed in the early 1970s by Dennis Ritchie at Bell Laboratories in USA.C was originally first implemented on the DEC PDP -11 COMPUTER IN 1972.C was originally designed for writing system software but today a variety of software programs are written in C.C can be used on many different types of computers but is mostly used with the unix operating system.
It is also called as ' Procedure oriented programming language '.
The C has now become a widely used professional language for various reasons
- Easy to learn
- Structured language
- It produces efficient programs
- It can handle low - level activities
- It can be compiled on a variety of computer platforms
Facts about C
- C was invented to write an operating system called UNIX.
- C is a successor of B language which was introduced around 1970.
- The language was formalized in 1988 by the American National Standard Institute ( ANSI ).
- The UNIX OS was totally written in C by 1973.
- Today C is the most widely used and popular System Programming Language.
- Today's most popular Linux OS and RBDMS My SQL have been written in c.
- C has been written in assembly language.C89/C90 and C99 are two standardized editions of c language.
Why use C ?
C is a very powerful and widely used language.It is used in many scientific programming situations.It forms ( or is the basis for ) the core of the modern languages JAVA and C++.It allows you access to the bare bones of your computer.C was initially used for system development work,in particular the programs that make-up the operating system.C was adopted as a system development language because it produces code that runs nearly as fast as code written in assembly language.
Some examples of the use of c Might be:
- Operating systems
- Language Compilers
- Assemblers
- Text Editiors
- Print Spoolers
- Network Drivers
- Modern Programs
- Data Bases
- Language Interpreters
- Utilities
It is a good idea to learn C because it has been around for a long time which means there is a lot of information available on it.Quite a few other programming languages such as C++ and java are also based on C which means you will be able to learn them easily in the future.
Definition of a Program?
A Computer Program is a set of instructions for a computer to perform a specific task.Programs generally fall into these categories applications,utilities or services.
Programs are written in a programming language then translated into machine code by a compiler and linker so that the computer can execute it directly or run it line by line ( inerpreted ) by an interpreter program.
what is a compiler ?
A Compiler is a computer program that translates human readable source code into computer executable machine code.
what is difference between compiler & interpreter is :
The major difference between Compiler & interpreter is :
Compiler translates the program (source code) into machine code in one go i.e. all lines of program simultaneously.Thats why all compiler based languages shows all errors together.
While interpreter translates the source code into machine code one statement at a time.Thats why program execution cannot proceed to next statement until the previous error is corrected.
Getting Started with CProgramming
The screen shown in the above contains the following parts.
- Menu bar
- Editior window
- Message window
- Status bar
We will now discuss each of these in brief.
Menu bar
The Menu bar displays various options.These options contain their corresponding pull - down menus which in turn several other options for reading and executing programs.
Editior window
This spacious window opens just below the menu bar.Programs are written in this window.
Message window
At the bottom of the editor window,another window known as message window is seen.This is the window where error messages ( if any ) are displayed after the program has been compiled.
Status bar
The status bar appears at the bottom of the screen.It carries a brief description of the option selected from the various menus of the menu bar.
A Simple C Program ( Program Structure )
The first thing we must do is open a text editor.Now type the following lines of code.
1. / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
2. / / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3. # include < stdio.h >
4. # include < conio.h >
5. void main ( )
6. {
7. clrscr ( ) ;
8. Printf ( " this is my first Program in c " ) ;
9. getch ( ) ;
10. }
Next step : ( 1 ) Compile the program ( Alt + F9 )
( 2 ) Compile the program ( ctrl + F9 )
Understanding the Program
Using comments
In the program 1,2 lines are comment statements .C supports single line and multi line comments.All characters available inside any comment are ignored by compiler.
/ / this is single line comment
/ * this is a block of statements * /
# include < stdio.h >
# include is called the preprocessor .It processes the source code before it is actually compiled. It tells the compiler to include, i.e. reading and inserting the contents pf the file stdio.h in the source code.Stdio is short for Standard input/output .The compiler recognizes the hash sign ( # ) as a command to perform the include operation at compile time.
The header file, stdio.h, has to be included at the begining of every program that uses input / output statements ( printf and scanf ). If we use printf and scanf statements in a program without including this header file at the begining of the program we will get a compile - time error.
# include < conio.h >
Clrscr ( ) and getch ( ) defined in this header file. Conio is short for Console input / output . The inclusion of this file in our program is necessary for using these two function.