Monday, September 10, 2012

C language

Short notes about of C language.
'C' was developed from an language 'Basic Combined Programing Language' called 'B' developed in the 1960's at Cambridge University 'B' language was modified by Dennis Ritchit and was implemented at Bell laboratories in 1972. The new language was named is 'C' since it was developed along with the Unix operating system it is strongly associated with Unix. Today 'C' is running under a number of operating systems including MS DOS.

Advantages or Importance of 'C' language.
1. Program written in 'C' are efficient and fast.
2. Several standard build in functions are available which can be used for developing programs.
3. 'C' is highly portable, programs written for one computer can be run on another with little or new modification.
4. It is robest can be used to write any complex program.

Features of 'C' language.

1. 'C' is a structured programming language hence.
2. Programs can be written quickly with less mistakes.
3. It increases the preadability of the programs and finaly, flexibility of the program is improved.
4. Sequence, condition and loop structures are present in 'C'.
5. 'C' is Case-sensitive.
6. 'C' Can reference a memory locations by means of it's address using pointers hence 'C' is suitable for system programming.
7. Every Statement in 'C' should end with a semi colon.

Structure of a 'C' program.
Documentation section
Link section
Definition section
Global declaration section
Main () funtion section
{
Declaration part
Executable part
}
Sub program section
Function 1
Funtion 2
.
.                       }- User defined function definitions
.
Function n

The Documentation section consist of a set of comment lines giving the name of the program author and explanation about program.

The link section provides instructions to the complies to link functions from the library.
The definition section defines all symbolic constants.

In the global declaration section variables that are shared by all the functions are declared.
Every 'C' program must contains main () section. The main () section contains 2 parts declaration part and executable part.

There declaration parts declares all the variables used in the executable part.
The is atleast one statement in the opening and closing brace the program execution beings at opening brace '{' and end at closing brace '}' whic is the logical end of program. All statement in the declaration and executable part end with semi colon.

The sub program section contains user defined functions definition.

Except main () function section all the other sections may be absent in a program when they are not required.

Short notes.
'C' Character set:

The characters in 'C' are grouped in to following categories.

1. Letters - A-Z, a-z
2. Digits - 0-9
3. Special characters.
4. White spaces.

'C' tokens:

Individual words and punctuation names are called tockens.

In a 'C' program the smallest individual units are known as 'C' tockens. They are grouped in to Identifiers, Keywords, Constants, Symbols and Operators.

Identifiers:

Identifiers refer to the names of the variable function and arrays. These are user-defined names.

Rules of Identifiers:

1. Identifiers may contain sequence of letters and digits with a letter as first character, 2. Both uppercase and lower case letters are commonly used but uppercase variable and lower case variable are permitted.

Example:
             main
             amount

Keywords:

All keywords have fixed meaning and these meaning cannot be changed. Keywords save as a basic building blocks for program statements all the keywords must be written in lower case.

Example:
            float
            white

Constants:

Constants refer to fixed values that don't change during the execution of a program 'C' supports several types of constants, as shown below.

Constants - Numeric, Character.
Numeric - Integer, Real.
Character - Single character, String.

Integer Constant:

They refer to sequence of digits there are three types of integers.

1. Decimal Constant: It consists of set of digits 0 of through 9. Example: -123, 9.
2. Octal Constant: It consists of set of digits 0 through 7 with leading 0. Example: 037, 0. Rules: May be precedent by on optional + or -.
3. Hexa Decimal Constant: A sequence of digits preceded by ox. They may also include alphabets A through F, 10 represent No. 10 to 15. Example: ox2, ox9F Rules: Embedded  spaces, Commas, & non digit characters are not permitted.

Real Constants:

These quantities refer to the nos containing fractional part A real no may also be expressed in exponential notation. Example: 0.00083, -0.75.

Single Character Constant:

A single character constant refer a single character closed with in pair of single quote mark character constant have integer value known as ASCII value. Example: 'S', 'X', 'A'.

Back Slash Character Constant or Escape Sequence:

'C' Supports some special back slash character constants that are used in output functions although they consist of 2 characters the represent one character. These character combinations are know as Escape sequences. For example in represents new line character.
'\a' - alert (bell).
'\b' - Back Space.
'\f' - form feed.
'\n' - New line.
'\r' - Charrage return.
'\t' - Horizontal tab.
'\v' - Vertical tab.
'\'' - Single quote.
'\"' - Double quote.
'\?' - Question mark.
'\0' - Null character.

String Constant:

A string constant is a sequence of characters enclosed in double quotes. Example: "Hello", "Good", "r".

No comments: