Tuesday, September 7, 2010

Fundamental of C:

a. Character Set:

Character represents certain information. In C program there are three different types of character are used such as alphabets (A-Z, a-z), Numerical Character (0-9) and Special Symbols ({#, &, /, %,’,”,>,<.>=.<=<,=}).

b. C Tokens:

The fundamental smallest unit of program is known as C tokens. Different tokens used in the programs are mention below:

1. Identifier

2. Variable

3. Constant

4. Key Words

5. Data Type

6. Operators

7. Escape Sequences

8. Format Specifier

9. Comment Characters

1.Identifier:
Identifier is a particular name given to a particular data. This name is used to identify and use that data.
An Identifier name can contain alphabets, numbers and special symbols underscore (”_”). However, the first character should not be the number and there should not be any space between two characters of an identifier. For e.g.: roll_no, a_a,etc.

2.Variable:
It is an identifier whose value can be change during the program excitation. While defining the variable one should define the type of data store by the variable.

3.Constant:
Constant is an identifier whose value remains unchanged through out he program excitation. While defining the constant its data type also should need to be defined. Constant are of two type: i) Literal Constant and ii) Symbolic Constant
A literal constant is defined with-in the program statement.

Symbolic constant are defined after header files. It has the format of # define constant name and constant value. For e.g.: #define pi 3.14.
On the basis of value constant. Constant can be following type:

4.Integer Constant:
Binary Integer(& 0,10,11,111)
Octal Integer (& 574,237)
Decimal Integer (& 987,957,895)
Hexadecimal Integer( & A, BD12,DE100)

Float point Constant:
Only for decimal & a=3.14 and & b=477.42
Character Constant:
Character constant is used for defining the defining the signal characters as constant. Signal character should be in closed with in a signal quotation mark (‘ ‘). E.g. Char. Section =’A’
String constant:
Char name [ ]. = “Ram”;
A string is a collection of characters. For defining a string constant the constant value are in-closed with in a double quotation mark [“ “].

4.Key Words:
Key Words are the reserve words whose meaning and used is fixed. We cannot change the key words as a variable or constant. Key words are also called the library words. There are32 key words in the C program. For example: int, float, for, if, char, union, struct, static, etc.

5.Data Type:
Data type defines the type of the data to be used in the program. The programmer should identify the data type of the variable or the constant before they are used in the program. There are three types of fundamental data type.
They are i) int ii) float iii) char
i) Int.
This data type is used for defining integer numbers. When a variable is defined as integer, it reserves 2 bytes memory space. Other variables of int. are shorter int(1 byte), and long int(4 bytes). Integer can be signed and unsigned.
For e.g. int a, b, sum;
ii) Float.
Float is used for defining an identifier which can store fractional number. It reserves 4 bytes of memory space for each identifier. Other variables of float are double (8 byte) and long double (10 byte). For e.g. float pi= 3.14
iii) Char.
Char is used to define an identifier which can store one character data or a string. It reserves one byte for one character. A character can be defining as singe or unsigned.

6.Operators:
Operator is an symbol that defines the operation to be performed betweens operations. In a statement a + b (“+”) is the operator and it determines the operation addition. Operation can be monadic or dyadic. A monadic or unary operation requires only one operand for example: i++, i--, (+) (-) is the monadic. A dyadic requires two operands for e.g. a+b, a-b, where (+) (-) is dyadic.
Operators can be classified into different types. They are:
i)Arithmetic Operator
ii)Relational Operator
iii)Logical Operator
iv)Assignment Operator
v)Increment/ Decrement Operator
vi)Conditional Operator
vii)Bitwise Operator
viii)Special Operator

i)Arithmetic Operator:
Arithmetic Operator are used for simple Arithmetic and mathematical calculation. Some of the arithmetical operators are mention below:

Operators Meaning
+ Addition
- Subtraction
* Multiply
/ Divide
% Modulo Division ( gives reminder incase of int.

ii)Relational Operator:
Relational operators are use for comparing the value of two operators. It is mainly used in case of condition, some of the relational operates are mentions below:

Symbols Meaning
> Grater than
< Smaller than
>= Grater than or equal to
<= Less than of equal to
== Is equal to
!= Not equal to

iii)Logical Operators:
Logical operators are used to combine two or more relational operators. There are three logical operators. They are:
Symbol Meaning
&& Logical AND
Logical OR
! Logical NOT

iv)Assignment Operators:
Assignment operators is used for assigning a value or a result of an expression to a variable or a constant. Equal to is used for assigning the value(“=”), the value. C program also supports compound assignment operators. Such as +=, -=, *=, /=, etc.
For e.g. i =+1 sum=sum + 5 vop= exp
i +=1 sum+ = 5 variable operation= expression
It has the format of vop= exp
Where, v= variable, op= arithmetic operation and exp= expression.
Prod= prod * (x+2)
Prod*= (x+2)

v)Increment/ Decrement Operator:
There are two increment and decrement operators ++ and --. ++ adds one to the variable where as – subtracts the values of the variable.
i.e. i++ is same as
i= i+1
i+=1
It can be prefixed as post fixed. i ++ is post fixed and ++i is pre fixed. Ni an post fixed expression the operation before expression the operation before incensement / decrement is performed first. Thus, the values will be intersegment. Whereas the pre fixed the value is changed first and other operations are performed later.

vi)Condition Operator:
The condition operator (?:) is used for testing the condition. The result of the conditional operators will be true or false value. It has the format of expression 1, expression 2, and expression 3.
For e.g. x= a>b? a: b; same as if (a>b) x=a; else x=b;

vii)Bitwise Operator:
Bitwise operators are used to perform the calculation using binary digits of bits. Different bitwise operators used are:
S.N. Name Symbol
1 Bitwise AND &
2 Bitwise OR
3 Bitwise XOR ^
4 Bitwise Complement ~
5 Sift Left <<
6 Sift Right >>

viii)Special Operators:
The special operators used are comma operator( ,).

7.Format Specifier:
Format specifier is a symbol which contains % followed by a character e.g. (%d), Format specifier defines the type of the data used in the progam. It is mainly used in printf and scanf statement. Some of the specifier used are:
%d = Integer
%f = Floating number
%c = Characters
%s = String
%s = Unsigned and Integer

8. Comment Character:
Comment characters are used explain or to provide help conditions. It used within a program to explain the logic of the statement or multiply statement. The statement within comment character will not exclude from the program when the output is generated. For e.g.
/* int a,b;
a=5;
b=10;
sum= a+b; */
9. Input / output Statement:
Output:
Printf
Syntax: printf (“ format specifier “, arg1, arg2,…………);
Example: printf(“ %d%d”, a, b);
Input:
Scanf
Syntax: scanf(“format specifier “ , & arg1, arg2,………….);
Example: scanf(“%d%d”, &a, &b);

0 comments:

Post a Comment