DECLARATION OF INTEGER (int) TYPE:
CASTING DATA TYPES:
Result type of arithmetic phrase depends of operand types inside it. When a phrase is consisted of various data types, result type is set by defined casting rules. Rules for casting various data types in C language are oriented to higher data type. There are two ways of casting data types in C:
· automatic (implicit)
· given (explicit)
Implicit Casting (automatic transformation) works in a way that a variable (operand) of data type that is smaller in length (than data type of second variable) (operand), transforming internally to variable of data type with longer number length. It may sound mixed up, but here is an example:
short int -> int -> unsigned int ->long int -> unsigned long int -> float -> double -> long double
This table shows standard automatic casting of one type of operand to another type of operand in binary phrases (according to MSDN Library for MS Visual C++ 6.0):
Operand Type | Automatic Casting |
One of operands is long double. | Second operand transforms to long double. |
Previous rule doesn’t apply, and one of operands is double. | Second operand transforms to double. |
Previous rule doesn’t apply, and one of operands is float. | Second operand transforms to float. |
Previous rules don’t apply, and none of operands is real type operand. | Integer casting is made by following rules:
|
Important: rules for integer and real data type casting can differ from one translator programs to another.
Exmple:
int a;
unsigned long b;
float f, g;
double d;
g = a + f; // a transforms to float
d = a + b; // a and b transform to unsigned long, adding
// is produced in unsigned long domain and then
// the result type unsigned long is transformed
// to double
Example:
long lm = LONG_MAX, l; // LONG_MAX = 2147483647
unsigned long um = ULONG_MAX; // ULONG_MAX = 4294967295
float f;
l = lm + 1; // result: -2147483648 (fill over to neg. field)
f = lm + 1; // result: -2147483648.000000 (result is made
// in long domain)
l = um + 1; // result: 0 (fill over)
f = um + 1; // result: 0.000000 (result is made in
// unsigned long domain)
Explicit Casting (given transformation) of data types has higher priority then automatic transformation. General declaration of explicit (given) cast (cast operator):
(data_type) operand
Operand can be variable or phrase.
Example:
a = (int) c;
b = (double)d + c;
If you continue this way, in a month or two you will be able to merge all into a book.
Great work.
I am corn-fused, I have been interested in learning a programming language for quite some time now but, never found the time to actually sit down and try and learn a language till 2 days ago. Before coming to this website I downloaded Code::Block ver. 1.0rc2 as an IDE to use. I have learned about loops and the famous(I guess) "Hello World". I thought I was doing ok but after reading the last couple chapters and then rereading them to try and understand everything you have put out...How do I say this tactfully?????? Do I really need to go back and learn this stuff completely inorder to Program?
its amazing. atlast i found a gud tutorial for C
SHOW LOTS OF INFO! SHOW US WHAT WE ARE LOOKING FOR!