http://www.cplusplus.com/
http://pt.wikibooks.org/wiki/Programar_em_C%2B%2B/Vari%C3%A1veis_e_constantes
http://pt.wikibooks.org/wiki/Programar_em_C%2B%2B
http://pt.wikibooks.org/wiki/Linguagem_c#Conte.C3.BAdo
http://pt.wikibooks.org/wiki/Introdu%C3%A7%C3%A3o_%C3%A0_Programa%C3%A7%C3%A3o
http://pt.wikibooks.org/wiki/Wikilivros:Biblioteca
http://www.java2s.com/Tutorial/C/CatalogC.htm
http://visualcplus.blogspot.com/2006/02/lesson-4-casting-data-types.html
Someone's going to assume I'm workaholic since it has passed less then twelve hours since my last programming post, but what the heck, I assume you are willing to learn since you're here - so here's fourth lesson for all of you. This lesson is about transformation (casting) of integers and real data types, and explanations why this job is necessary in C language for compiler to understand the syntax. It's a short one, but with compressed value.
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):
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;