Data type
Data types
are the keywords that are used to define the type of value that a variable can
store all
c
compilers support three fundamental data types. They are
1. Integer (int)
2. Floating point (float)
3. Character (char)
1. Integer Data types
This type of data can bold numeric values without
decimal point or fractional part. The size of integer data type depends on the
operating system used. It occupies 2byte space in 16 bit operating system and 4
byte space in 32-bit operating system. C has three classes of integer storage,
namely short int, int, and long int in both signed and unsigned forms.
2. Floating data type
It is a data type which holds decimal part as its
value. They occupy 4 byte space in both 16 bit and 32 bit operating system .
Floating point numbers are defined in c by the keyword float. The extended forms
of floating point data are double and long double.
3. Character data type
This type of data can hold single character and
are enclosed within single inverted commas. It occupies one byte space in
memory of computer.
Operator
An operator is a symbol that tells the computer
to perform certain mathematical or logical operations. Operations are used in
program to manipulate data and variables. C supports different types of
operators. They are:
1. Arithmetic Operators
Operators that are used for arithmetic
calculations are known as arithmetic operators. C provides all basic arithmetic
operators. They are listed below:
| Operators | Meaning |
| +(plus) | Additions |
| - (Minus) | Subtractions |
| * (Multiply) | Multiplication |
| /(Slash) | Division |
| %(Percentage) | Modular Division |
2. Relational Operators
The Operators that are used to compare two
quantities are called relational operators. The different types of relational
operators are used in C as follows:
| Operators | Meaning |
| > | is greater than |
| >= | is greater than or equal to |
| < | is less than |
| <= | is less than or equal to |
| == | is equal to |
| != | is not equal to |
3. Logical Operators
Logical Operators are used to combine two or more
relational operator i.e. to test more than one condition simultaneously. The
different types of conditional operators used in C are as follows:
| Operators | Meaning |
| && | Logical AND |
| | | | Logical OR |
| ! | Logical NOT |
4. Assignment Operators
An assignment operator is used to assign the
result of an expression to a variable. The commonly used assignment operator is
'=". In addition C has a shorthand set of assignment operator of the
form
Vop=exp
where, V is a variable, op is an arithmetic operator and exp is an expression.
Example:
a=a+1 is equivalent to a+=1
a=a+b+c
a+=b+c
5. Increment and Decrement Operators
C has
two very useful operators that not generally found in other languages. These
are the increments (++) and the decrements (--) operator. The operator ++
increments the value of operand involved by 1 and the operator -- decrements
the value of operand involve by 1. Both are unary operator and take the
following form: ++M, M++ and --M, M--
The
prefix operators increments the value before statement execution and postfix
operator increments value after statement execution.
6. Conditional Operators
A
ternary operator pair?: is available in C to construct the conditional expression
of the form exp1?exp2:exp3; where exp1,exp2 and exp3 are the expression.
Exp1
is evaluated first. If it is non-zero then the exp2 is evaluated and becomes
the value of the expression. I f exp1 is false then exp3 is evaluated and its
becomes the result.
Example:
x=15, y=10, z=x>y?x:y;
7. Bitwise Operators
Bitwise
operators are the operators used for manipulation of data at bit level. These
operators used for manipulation of data at bit level. These operators are used
for testing the bit or shifting them right or left. Bitwise operators may not
applied to floating point data. The Bitwise operators and their meaning are as follows:
| Operators | Meaning |
| & | Bitwise AND |
| | | Bitwise OR |
| ^ | Bitwise EXOR |
| << | Bitwise Shift Left |
| >> | Bitwise Shift Right |
8. Special Operators
C
support some special operators such as commas operator, size of operator,
pointer operator (& and *), member selection operator (. and ->).
Commas
operator can be used to link the related expressions together. The size of
operator is a compile time operator and is used for dynamic memory allocation.
No comments:
Post a Comment