Saturday, 27 July 2013

BASIC ABOUT C LANGUAGE

 Programming

To solve a computing problem, its solution must be specified in terms of sequence of computational steps such that they are effectively solved by a human agent or by a digital computer.

Programming Language

1)            The specification of the sequence of computational steps in a particular programming language is termed as a program
2)            The task of developing programs is called programming
3)            The person engaged in programming activity is called programmer




Introduction to C Programming 
C is a general-purpose computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system. C is a structured programming language, which means that it allows you to develop programs using well-defined control structures (you will learn about control structures in the articles to come), and provides modularity (breaking the task into multiple sub tasks that are simple enough to understand and to reuse). C is often called a middle-level language because it combines the best elements of low-level or machine language with high-level languages. 


Where is C useful?
C’s ability to communicate directly with hardware makes it a powerful choice for system programmers. In fact, popular operating systems such as Unix and Linux are written entirely in C. Additionally, even compilers and interpreters for other languages such as FORTRAN, Pascal, and BASIC are written in C. However, C’s scope is not just limited to developing system programs. It is also used to develop any kind of application, including complex business ones. The following is a partial list of areas where C language is used: 
  1.           Embedded Systems           
  2.         Systems Programming
  3.         Artificial Intelligence
  4.         Industrial Automation
  5.         Computer Graphics
  6.         Space Research

Why you should learn C? 
You should learn C because:
·                     C is simple.
·                     There are only 32 keywords so C is very easy to master. Keywords are words that have special meaning in C language.
·                     C programs run faster than programs written in most other languages.
·                     C enables easy communication with computer hardware making it easy to write system programs such as compilers and interpreters.

WHY WE NEED DATA AND A PROGRAM
Any computer program has two entities to consider, the data, and the program. They are highly dependent on one another and careful planning of both will lead to a well planned and well written program. Unfortunately, it is not possible to study either completely without a good working knowledge of the other. For that reason, this tutorial will jump back and forth between teaching methods of program writing and methods of data definition. Simply follow along and you will have a good understanding of both. Keep in mind that, even though it seems expedient to sometimes jump right into coding the program, time spent planning the data structures will be well spent and the quality of the final program will reflect the original planning.

How to run a simple c program
1.  Copy Turbo c/c++ in computer
2.  Open c:\tc\bin\tc.exe
3.  A window appears
4.  Select File->new to open a new file
5.  Type the following program on editor




#include <stdio.h>
void main()
{
            printf(“hello”);
}

6. compile the program by pressing ALT+F9
7. Run the program by pressing CTRL +F9
Note:
1. C is case sensitive
2. Always terminate statements with semicolon.
3. A program starts with main()

Explanation of program
#include is known as compiler directive. A compiler directive is a command to compiler to translate the program in a certain way. These statement are not converted into machine language but only perform some other task.
main() is a function which the staring point for complier to start compilation. So a function must contain a main() function.



DETECTION AND CORRECTION OF ERRORS
Syntactic errors and execution errors usually result in the generation of error messages when compiling or executing a program. Error of this type is usually quite easy to find and correct. There are some logical errors that can be very difficult to detect. Since the
output resulting from a logically incorrect program may appear to be error free. Logical errors are often hard to find, so in order to find and correct errors of this type is known as logical debugging. To detect errors test a new program with data that will give a known answer. If the correct results are not obtained then the program obviously contains errors even if the correct results are obtained.



Linear Programming
Linear program is a method for straightforward programming in a sequential manner. This type of programming does not involve any decision making. General model of these linear programs is:
1.      Read a data value
2.      Computer an intermediate result
3.       Use the intermediate result to computer the desired answer
4.      Print the answer
5.      Stop

Structured Programming
Structured programming (sometimes known as modular programming) is a subset of procedural programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify. Certain languages such as Ada, Pascal, and dBASE are designed with features that encourage or enforce a logical program structure.
Structured programming frequently employs a top-down design model, in which developers map out the overall program structure into separate subsections. A defined function or set of similar functions is coded in a separate module or sub module, which means that code can be loaded into memory more efficiently and that modules can be reused in other programs. After a module has been tested individually, it is then integrated with other modules into the overall program structure.

Advantages of Structured Programming
1.      Easy to write:
Modular design increases the programmer's productivity by allowing them to look at the big picture first and focus on details later.Several Programmers can work on a single, large program, each working on a different module. Studies show structured programs take less time to write than standard programs. Procedures written for one program can be reused in other programs requiring the same task. A procedure that can be used in many programs is said to be reusable.
2.      Easy to debug:
Since each procedure is specialized to perform just one task, a procedure can be checked individually. Older unstructured programs consist of a sequence of instructions that are not grouped for specific tasks. The logic of such programs is cluttered with details and therefore difficult to follow.
3.      Easy to Understand:
The relationship between the procedures shows the modular design of the program. Meaningful procedure names and clear documentation identify the task performed by each module. Meaningful variable names help the programmer identify the purpose of each variable.
4.      Easy to Change:
Since a correctly written structured program is self-documenting, it can be easily understood by another programmer.

Structured Programming Constructs
      It uses only three constructs -
  • Sequence (statements, blocks)
  • Selection (if, switch)
  • Iteration (loops like while and for)




Types of Programming Language

Low Level Language
First-generation language is the lowest level computer language. Information is conveyed to the computer by the programmer grey_loader
as binary instructions. Binary instructions are the equivalent of the on/off signals used by computers to carry out operations. The language consists of zeros and ones. In the 1940s and 1950s, computers were programmed by scientists sitting before control panels equipped with toggle switches so that they could input instructions as strings of zeros and ones.

Assembly Language
Assembly or assembler language was the second generation of computer language. By the late 1950s, this language had become popular. Assembly language consists of letters of the alphabet. This makes programming much easier than trying to program a series of zeros and ones. As an added programming assist, assembly language makes use of mnemonics, or memory aids, which are easier for the human programmer to recall than are numerical codes.

Assembler
An assembler is a program that takes basic computer instructions and converts them into a pattern of bits that the computer's processor can use to perform its basic operations. Some people call these instructions assembler language and others use the term assembly language In other words An assembler is a computer program for translating assembly language — essentially, a mnemonic representation of machine language — into object code. A cross assembler (see cross compiler) produces code for one processor, but runs on another.

High Level Language
The introduction of the compiler in 1952 spurred the development of third-generation computer languages. These languages enable a programmer to create program files using commands that are similar to spoken English. Third-level computer languages have become the major means of communication between the digital computer and its user. By 1957, the International Business Machine Corporation (IBM) had created a language called FORTRAN (FORmula TRANslater). This language was designed for scientific work involving complicated mathematical formulas. It became the first high-level programming language (or "source code") to be used by many computer users.Examples : C, C++, Java, FORTRAN, Visual Basic, and Delphi.



Interpreter
An interpreter is a computer program that executes other programs. This is in contrast to a compiler which does not execute its input program (the source code) but translates it into executable machine code (also called object code) which is output to a file for later execution. It may be possible to execute the same source code either directly by an interpreter or by compiling it and then executing the machine code produced.

COMPILER
A program  that translates source code into object code. The compiler derives its name from the way it works, looking at the entire piece of source code and collecting and reorganizing the instructions. Thus, a compiler differs from an interpreter, which analyzes and executes each line of source code in succession, without looking at the entire program. The advantage of interpreters is that they can execute a program immediately. Compilers require some time before an executable program emerges. However, programs produced by compilers runmuch faster than the same programs executed by an interpreter.

Fourth Generation Language
Fourth-generation languages attempt to make communicating with computers as much like the processes of thinking and talking to other people as possible. The problem is that the computer still only understands zeros and ones, so a compiler and interpreter must still convert the source code into the machine code that the computer can understand. Fourth-generation languages typically consist of English-like words and phrases. When they are implemented on microcomputers, some of these languages include graphic devices such as icons and onscreen push buttons for use during programming and when running the resulting application.
Many fourth-generation languages use Structured Query Language (SQL) as the basis for operations. SQL was developed at IBM to develop information stored in relational databases. Examples of fourth-generation languages include PROLOG.
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------

No comments:

Post a Comment