Type modifier
|
||||||||||||||||||||||||||||||||||||||||
The basic data types may have modifier preceding
them to indicate special properties of the object being declared.
|
||||||||||||||||||||||||||||||||||||||||
These modifiers change
the meaning of the basic data types to suit the specific needs.
|
||||||||||||||||||||||||||||||||||||||||
These modifiers are
unsigned, signed, long and short. It is also possible to give these modifiers
in combination, e.g., unsigned long int.
|
||||||||||||||||||||||||||||||||||||||||
eg:-
|
||||||||||||||||||||||||||||||||||||||||
Modifier for char Data Type
|
||||||||||||||||||||||||||||||||||||||||
main()
|
||||||||||||||||||||||||||||||||||||||||
{
|
||||||||||||||||||||||||||||||||||||||||
char ch=291;
|
||||||||||||||||||||||||||||||||||||||||
printf("%d\t%c\n",ch,ch);
|
||||||||||||||||||||||||||||||||||||||||
}
|
||||||||||||||||||||||||||||||||||||||||
output:- 35
|
||||||||||||||||||||||||||||||||||||||||
Here ch has been
defined as a char ,and char cannot take a
value bigger than +128.That is why assigned value of ch is 291 and
is considered to be 35 (291-128-128).
|
||||||||||||||||||||||||||||||||||||||||
|
Evaluation of expression
|
||||||
An expression is a combination
of variables, constants and operators arranged
according to the syntax of the language.
|
||||||
C can handle any complex expression
with ease.
|
||||||
It is little bit different from
algebraic expression.
|
||||||
|
||||||
Evaluation of expression:
|
||||||
We can evaluate an expression by
using assignment statement. As
|
||||||
Variable = Expression.
|
||||||
e.g. :
|
||||||
Temp = ((f * cos(x)/sin (y))+(g *
sin(x)/cos(y)))
|
||||||
All relevant variables must
be assigned values before the evaluation of the expression.
|
||||||
Type conversion in expression:
|
||||||
To effectively develop C programs, it
would be necessary for you to understand the rules that are used for
the implicit conversion of operands.
|
||||||
If an expression contains an
operation between an int and a float, the int would
be automatically promoted to a float before carrying out of
operation.
|
||||||
Automatic type conversion
|
|||||||||||||||||||||
If the operands are of different
types the lower type is automatically converted to the higher
typebefore the operation proceeds
|
|||||||||||||||||||||
The result is of the higher
type
|
|||||||||||||||||||||
Given below is the sequence of rules
that are applied by evaluating expressions.
|
|||||||||||||||||||||
|
|||||||||||||||||||||
Final result of an expression to the
type of the variable on the left of the assignment signed
before assigning the value to it.
|
|||||||||||||||||||||
However, the following changes are
introduced during the final assignment:
|
|||||||||||||||||||||
1. Float to Int causes
truncation of the fractional part.
|
|||||||||||||||||||||
2. Double to float causes
rounding of digits.
|
|||||||||||||||||||||
3. Long int to int causes
dropping of the excess higher order bits
|
|||||||||||||||||||||
Type Casting:
|
|||||||||||||||||||||
Casting a value is a forcing a type
conversion in a way that is different from the automatic conversion and this
process is called type cast.
|
|||||||||||||||||||||
Type Definition using typedef
|
|||||||||||||||||||||
C allows us to create data types via
the typedef statement.
|
|||||||||||||||||||||
The format of typedef statement is:
|
|||||||||||||||||||||
typedef data type new_type_name;
|
|||||||||||||||||||||
Example:
|
|||||||||||||||||||||
typedef int units;
|
|||||||||||||||||||||
units bat1,bat2; /*this statement is
equivalent to int bat1,bat2*/
|