1. The program type value
- value (literal) program also Type: Specifies the type or the default type
Default Type: 2 int, 0.2 is double, 'c' is char
Specify the type: 0.2f to float (the suffix f denotes a float)
-C language is strictly typed language, there are literal types, need to consider the type of use literals
2. Question: If different types of variables (literal) assigned to each other, what happens?
Example Analysis:
Programming Experiment: between different types of assignments
Experimental results:
- large type assigned to the small type, may overflow
When the value in a small range of types - "assignment success
When the value exceeds the range of the small type - "overflows
- small type can be assigned to the security of large type
- floating-point type assigned to an integer truncation occurs (the fractional part is missing)
- integer assigned to the floating-point type, can be completed successfully
2. Type Conversion
When the assignment operation or between different types of variables in the C language (variable value), the type of conversion occurs. Converter does not change the type of the original variables.
Example Analysis:
tips
- development environment (compiler software) by the editor and compiler composition
Editor: responsible for the preparation of programs (word processing software)
Compilers: compilers responsible for the program (text becomes binary)
-C language compiler to check types at the same time, may make the default conversion
Casts (display type conversion)
-C languages can be cast
- grammar rules: type name = (type) var;
- Example:
Programming test: casts
Note: the program should try to avoid the conversion between different types of data types
4. Summary
- different types of variables (variable value) assigned type conversion occurs
- The type of conversion does not change the value of the original variable
- can represent different types of a range between, and therefore may cause an error type conversion
-C languages can be cast (cast)
- the program should try to avoid the type of conversion