Arithmetic operators.

'C' provides all the basic arithmetic operators. They are listed in table. The operators +, -, * and / all work the same way as they do in other language.

Operator: +, Meaning: Addition or unary plus.
Operator: -, Meaning: Subtraction or unary minus.
Operator: *, Meaning: Multiplication.
Operator: /, Meaning: Division.
Operator: %, Meaning: Modulo division.

Examples of use of arithmetic operators are:

a-b a+b
a*b a/b,
a%b -a*b.

Here a and b are variables and are known as operands. The modulo division operator % cannot be used on floating point data.

Integer Arithmetic:

Examples, if a and b are integers then for a = 14 and b = 4 we have the following results.

a-b = 10
a+b = 18
a*b = 56
a/b = 3 (Decimal part truncated).
a%b = 2 (Remainder of division)

Real Arithmetic:

An arithmetic operation involving only real operands is called real arithmetic. If x, y and 2 are floats, then we will have

x = 6.0/7.0 = 0.857143.
y = 1.0/3/0 = 0.333333

Programming in ANSIC:

z = -2.0/3.0 = -0.666667

The operator % cannot be used with real operands.

Mixed - mode Arithmetic

When one of the operand is integer in the expression. If either operands is of the real type, then only the real operation is performed and the result is always a real number. Thus,

15/10.0 = 1.5

Where as

15/10 = 1

...

Operators and Expression.

An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations operators are used in programs to manipulate data and variables. Thus usually form a part of the mathematical or logical expression.

'C' operators can be classified in to a number of categories they include,
1. Arithmetic operators.
2. Relational operators.
3. Logical operators.
4. Assignment operators.
5. Increment and decrement operators.
6. Conditional operators.
7. Bit wise operators.
8. Special operators.

An expression is a sequence of operands and operators that reduces to a single value.

Data types in 'C'.

Storage representations and machine instruction to handle constants differ from machine to machine. 'C' supports 4 classes of data types.

1. Primary or fundamental data types .
2. User defined data type.
3. Derived data type.
4. Empty data set.

Primary data type:

'C' Compilers support four fundamental data types, namely integer (int), character (char) floating point (float), and double precision floating point (double) many of them also after extended data types long int, short int.

Integer type:

Integers are where with a range of values supported by a systems in order to provide control over range of nos and storage namely short int, long int, int in both signed and unsigned form int requires only half amount of storage space as that of int unsigned integer use all the bits for the magnitude of number and are always positive.

Floating point type:

They store real nos in 32 bits with 6 digits of precision A double data type uses 64 bits giving a precision of 14 digits. A long double also stores real nos in 80 bits.

Character type:

A single character can be defined as a character type data. They are usually stored in 8 bits.

Data type: Character or (Signed character). Keyword: Char or Signed char. Sine in bits: 8.

Data type: Unsigned Character. Keyword: Unsigned char sine in bits: 8.

Data type: Integer or Signed Integer. Keyword: int or signed int. Sine in bits: 16.

Data type: Unsigned Integer. Keyword: Unsigned int Sine in bits:16.

Data type: Short Integer or Signed Short Integer. Keyword: Short int or Signed short int. Sine in bits: 8.

Data type: Unsigned Short Integer. Keyword: Unsigned short int. Sine in bits: 8.

Data type:  Long Integer or Signed Long Integer. Keyword: Long int or Signed long int. Sine in bits: 32.

Data type: Unsigned Long Integer. Keyword: Unsigned long int. Sine in bits: 32.

Data type: Float. Keyword: Float. Sine in bit: 32.

Data type: Double. Keyword: Double. Sine in bits: 64.

Data type: Long Double. Keyword: Long Double. Sine in bits: 80.

User defined data type:

 'C' supports a feature known as "type definition" that allows users to defined on identifiers that could represent existing data type. These can be used to declare other variable.

Syntax:

type def <type> <identifier>

Example:

type def int ints;
units b1, b2.

Here for int we have given a new name units. Hence b1, b2, is also of type integer 'C' also supports another user defined data type called as enumenated data type which can be used to declare variables that can have one of the values enclosed with in braces.

Syntax:

enum <identifier> {value1, value2,....valuen};

Exmaple:

enum day {mon, tue, wed};

Here mon is equal to 1, tue=2, wed=3. (which are automatically initialized).

enum day birthday; now birthday can have any one of the value(1,2,3).

Derived data type:

Arrays functions, structures and pointers are called as derived data types.

Syntax:

data type v1, v2.....}

Example:

in a1, a2;

Declaration of variable tells the compiler what is the variable name. It specifies the type of data which the variable will hold.

Variable, Symbols and operators.

A Variable is data name that may be used to store a data value it remains changed during the execution as a program example it takes different values at different times. It is a symbolic name given to the memory location where the data is stored the user is allowed to access the memory location through this variables name are declared in the begining of a program before the executional statements in the program.

Rules for Variables:

1. They must begin with letter some systems permit underscore as the first character.
2. ANSI 'C' recognizes 31 characters. But generally 8 characters are used for variable naming.
3. Uppercase lower case variables are treated as different variables.
4. Variable name should not be a keyword.
5. White space is not allowed.

Example:

Name
Place
Age
x1
R-Value

Symbols and Operators:

'C' Supports some special characters for specific purposes.

Example:

[ ]
( )

Operator is a symbol which performs some action on operators.

Example:

+, -, *, /, %, <, >, >=, <= etc.

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".

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.

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.

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.

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.

Multi Program Batch System.

Student provides and important data structure: A job pool.

A job pool on discovers the OS to select which job run next, to increase CPU utilization.

1. When a job came in directly on cards on even or magnatic tape, It is not possible to run a job in a different order they must be runes sequently or FCFS (First Come First Serve).

2. When jobs are in direct access device. Such as it is disc job scheduling became possiable.

The most important aspect of job scheduling is a ability to multi program. Multi program mean increases CPU utilization by organizing jobs such that the CPU always has one to execute.

The idea is follows the operating system keeps several jobs in a memory at a time. The set of jobs is a subset of the job kept in the Job pool.