Integer automatic conversion principle in C language

xiaoxiao2021-03-06  58

The following experiments have the following experiments in the Virual C 6 between Virual C 6, and some developers know that these things are extreminated. All operands are automatically converted to unsigned types when there is a symbol type and unsigned type. Therefore, in this sense, the operational priority of unsigned number is higher than the number of symbols, which is often important for embedded systems that should be used frequently in unsigned data types. First, one experiment is performed, define a signed INT data and unsigned INT data, and then compare the size: unsigned int a = 20; signed int b = -130; A> B? Or b> a? Experimental proven B> a, that is, -130> 20, why does this result? This is because in C language operation, if you encounter an operation between the unsigned number and the symbol number, the compiler will automatically convert to the non-symbol number to process, so a = 20, b = 4294967166, this is more B> a. Again, unsigned int a = 20; signed int b = -130; std :: cout << a b << std :: endl; result output is 4294967186, the same reason, before the operation, A = 20 , B is converted to 4294967166, so A B = 4294967186

The subtraction and multiplication calculation results are similar. If the B = -130, B is operated as a Signed INT data does not affect the type of B, the calculation results are still signed int b = -130; std :: cout << b 30 << std :: endl; output is -100. For floating point numbers, floats (FLOAT, DOUBLE) are actually symbolic numbers, unsigned and signed prefixes can not be added to Float and Double, of course, there is no transformation between symbolic number without sign numbers. The problem is.

转载请注明原文地址:https://www.9cbs.com/read-71263.html

New Post(0)