[4] C language learning record type conversion

C language data types may be converted:

1) cast

2) implicit type conversion

Cast syntax:

- (Type) var_name; the variable name

- (Type) value; variable value

Forced conversion result type:

- the target type can accommodate target: the results unchanged

- the target type can not accommodate target: the target will generate truncated.

note:

Not all of the cast can succeed, when it is not mandatory conversion, the compiler will generate an error message.

On 32-bit machines, the address of the global variable occupies four bytes.

Implicit type conversions: active typecast compiler.

(In engineering development, some compiler bug is caused by an active implicit type conversions.)

note:

       Type low-to-high type implicit conversion is safe, no truncation;

       High-low type to the type of implicit conversion is unsafe, it can lead to incorrect results.

Implicit type conversion occurred points:

1) arithmetic formula, a low to a high conversion type type;

2) assignment expression, the value is converted to an expression of the type variable on the left;

3) The function is called argument conversion parameter type;

4) function returns the value, return type of the return value is converted to an expression;

 summary:

Guess you like

Origin blog.csdn.net/haibing_x/article/details/94411349