Monday, March 3, 2008

Constants:-
Fixed values that do not change during the execution of a program is called a constant. A constant is a quantity which is stored at a location in the memory of computer.

Types of constants




Constants




Numeric constant Character constants




Integer constants Real constants Single
Character constant String constant




Integer constant:-
An integer constant refers to a sequence of digit .
Rules for Integer Constant:


(1) An integer constant must have atleast one digit.
(2) It must not have decimal point.
(3) It could be either + ve or - ve.
(4) No commas or blanks are allowed.
(5) The allowable range for integer constant is -32768 to + 32767


Real constant:-

Real constants are often called floating point constants. Real constants could be written in two forms fractional & exponential form.

Mantissa & exponent
8*103 -E

Rules for Real constant:-
1 Real constant must have a decimal point.
2. Default sign is + ve.
3. Range ( of real constants expressed in exponential form-3.4 e 38 to 3.4 e 38)
4. Must have atleast one digit.
5. Commas & blanks are not allowed.
6. Could be either positive or negative.

Single character constant:-
A single character constant contains a single character enclosed with in a pair of single quotes . eg. ' A'

String constant :
A string constant is a sequence of characters enclosed in double quotes . eg. " A"

Rules for constructing character constant:
A character constant is a single alphabet., a single digit, a single special symbol enclosed with in single inverted commas. Both the inverted commas should point to the left.

Maximum length of a character constant can be characte.
Escape sequence / Backslash char. Constant:-


void main ( )
{
Int a = 2:
print if ( "\n % d/t = ",a);
getch ( );
}

Backslash character constant are used in output functions. These characters combinations are known as escape sequence.
eg. ' \n' stands for newline character.
'\b' for backspace



VARIABLES

A variable names are names given to location in the memory of computer where different constants are stored.
A variable name can be chosen in a meaningful way so as to reflect its function or nature in the program.


Rules for variables forms:

1. They must begin with a letter.
2. ANSI standard recognizes a length of 31 characters. However the length should not be more than 8 characters.
3. Upper case & lower case are significant a, A : have different meanings
4. A variable name should not be a keyword.
5. No commas & blanks are allowed.
6. No special symbol except underscore.

Data Type


Scalar/ Primary User defined Derived Empty set Pointer







Int, Float, Double, char Type defined , enumerated Structured, Union, array

(1) Int data type:
C has 3 classes of Int.storage.

(1) Short int , int and long int
(b) signed S. N Type Size Range
(c) Unsigned 1 Char or signed 1 -128 to
2 Unsigned char 1 0 to 255

3 Int or signed int 2 -32768 to 32767
4 Unsigned int 2 0 to 65535
5 Short int or signed short 1 -128 to 127
6 Unsigned short int 1 0- 255
7 Long int or signed 4



Int.

These int. are of type integer (i. e without decimal . It requires 16 bits i.e 2 bytes to store a data. It is range is from -32768 to +32767

Shrort int:-
It requires one byte (8 bits ) of memory space.
Long int:-
It requires 32 bits to store a data.
Signed or simple int:- It requires some memory space i.e 16 bits or 2 bytes
Floating point data types:-
Floating point no are stored in 32 bits ( 4 bytes)with 6 digits of precisions . It 's range is from +3.4e -38 to 3.4 e +38

Double ( Highest priority)
A double data type uses 64 bits ( 8 bytes) giving a precision of 14 digits . It 's range is from 1.7 e-308 to 1.7 e +308 . To extent the precision further we may use long double which uses 80 bits.
Character data types:-
A single character can be defined as char data type. It is stored in 8 bits ( 1 byte) of internal memory . It's range is from -128 to +127 . Characters can be signed or unsigned . By default char. are always signed. Unsigned char have values between 0 to 255.
Unsigned int:-

Range from 0 to 65535
(B) User defined data types
c supports 2 user defined data types.
1. Type Definition.
2. Enumerated data type.

(1) Type Definition
C supports feature known as type def .that allows user to define an identifier that would represent an existing data type.
type def type identifier
where type refers to an existing data type & identifier refers to new name given to that data type.
type def int a ;
a count;
(1) Enumerated data type:-
The second user defined data type is enumerated data type . It is defined as followed:
enum identifier { value 1, value2,..........value n},
Identifier is a user defined enumerated data types which can be used to declare values . The enumerated have values v1, v2, v3,............ vn can only have on values . The computer automatically assigns int digit beginning with zero to all the enumerated constants. However the automatic assign int can be over - ridden by assigning values explicitly.

Operators:-
As C is rich in data types, same as C is rich in operators . An operator is a symbol that tells the computer to perform mathematical or logical manipulation . Operators are used in programs to manipulate data & variables.

Used for processing.
C supports following types of operators.
1 Arithmetic operators A-L
2 Relational operators R-A
3 Logical operators L-I
4 Assignment ,, A-R
5 Increment & Decrement operators I-B
6 Conditional ,, ,, C-C
7 Bitwise ,, ,, B-S
8 Special ,, ,, S-A

1) Arithmetic operators:-
Used in all computer languages, c provides all basic arithmetic operators. These were designed at the time of Abacus compuling

+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus division (int)


Eg. Operands



a+b



Operator

4/2 = 2
5%2 = 1( Remainder, Floating point)
2 Relational operators:- C supports 6 relations operations. Used to create logical relationship between two operands. Used for comparison purpose
< Less than
> Greater than
<= is less than or equal to
>= is greater than or equal to
= = is equal to
! = is not equal to

A= = S
A = S

used for logical operations
3 Logical operators :

C has 3 logical operators.
&& logical And
!! Logical OR
! Logical NoT
The logical operator && and !! are used to test the more than ones condition
4 Assignment opeator :-
Assignment operator are used to assign the result of an expression to a variable "="

V op = Exp;
a = 5 Assigning a is 5



x = x-1 x = x+1
x - = 1 x+ = 1

5) Increment & Decrement operators / counter operator :-

The increment operator (+) adds one to the operand & while decrement (- - ) operators subtract one.
Prefix operator :
First of all value will be assigned to variable & then increment

Prefix :- ++ m Post fix :- m ++
- - m m - -

6) Conditional operator / Ternary operator :-
It is also called tornary operator . It is a pair of " ? :"



exp 1 ? exp 2 : exp 3 ;


If (a >b)
x = a
else
x = b


? a : b 'Conditional'


7) Bitwise operators :
C has 6 bitwise operators for manipulating data at bit level, Bitwise operators may not to be applied to float or double .Faster than other opertors.


& Bitwise And
! Bitwise OR
^ Explusive OR
<< shift left
.>> shift Right
~ one's complement
& bitwise And

The AND operators on 2 operands.


A B &
0 0 0
0 1 0
1 0 0
1 1 1
1Byte = 8 bits
Truth table


! Bitwise OR 2 bits high/low

A B ^
0 0 0
0 1 1
1 0 1
1 1 1


A exclusive OR ( X OR) 2 Bites

A B
0 0 0
0 1 1
1 0 1
1 1 0

<<
= 2 bytes

1 001010
1 Bit shift left
 0010100
>> 1 Bit right
0000101010

Right sheft 00010101

~ Compliments
0 0101101

~ Compliment
110100110
8) Special opertor:-
Special operator for low level programs:-
(1) common operators:This can be used do link related expressions together.
used in pointers, structures, unions
value = ( lx =10, y = 5 , x+y);
(2) Size of operator:-
The size of operator is a compile kind operator, when used with operand it returns the no. of bytes the operand occupies.



n = size of (long int)
Print if(" % d", n);



(3) Uniary operator :-
These are used for identification of a no. whether it is signed or unsigned.
y = 15 -(-12)
(4) Pointer operator : -
There are two pointer operators
a) Ampersand (&)
It is operator " address of "

5) Star:-
This is the pointer operator " address at value"
Int p, n,q P &
q = & p [15]
n = *q
6) Member selection operator
These are used in structure & unions
a) Dot ( . )
(b) Relational operator
Each operating system has its own facility for inputting & outputting data from < to files to devices & devices.