C language forced conversion problem! Hello! Step by step, int a, b; The function of this sentence is that the operating system allocates a free storage space for variables A and B respectively. Using A and B will be equivalent to accessing their corresponding storage space A = 0000b = ox1234; The function of this sentence is to put 0000 in the storage space corresponding to variable A and 0x 1234 in the storage space corresponding to variable B. The key point is the following sentence: a = (char)(b). Its function is equivalent to modifying the value of variable A. Specifically, it takes out the value of B from the storage space corresponding to B, that is, 0x 1234, and then converts it into char type. Then put the converted result into the storage space corresponding to variable A, that is, overwrite the original 0000. What is the result of the transformation? The calculation is as follows: usually in C, int type accounts for 4 bytes, and char type accounts for 1 byte. If the data of type int is output as type char, then the compiler will automatically discard the contents of the first three bytes of type int. The data of type int corresponding to this problem is hexadecimal 0X 1234, which is stored in the computer as follows: 00000000000101100 * * After four bytes are converted into char type, the first three bytes are discarded. That is, the result is 00 1 1065438. When the statement a = (char)(b) is executed, the value of this 1 byte, that is, 52, is put into the variable A instead of the original 0000. The data types of variables A and B are not changed in the whole process. They used to be int types. Now, The program only modified the value of the variable A, and even the value of B was not modified, because when modifying the value of A, the value of B was only taken out from the storage space corresponding to B, and the result was modified to char type, but he put the modified result in the storage space corresponding to A, but not in the storage space corresponding to B, so the original value corresponding to B was not overwritten. It used to be 0X 1234, but now it is 0X 1234, for reference only! Hmm. How interesting
(rData+3 *(long)tmprawdata 0- 1024 l))/ 10l);
That is, RDATA+(3 * (temporary raw data 0- 1024))/ 10.
The L at the back stands for long plastic surgery,
* and/are operators with the same priority, calculated from left to right.
TempRawData0 subtracts 1024, then multiplies it by 3, then divides it by 10, and then adds rData.
Forced type conversion in c language. Forced type conversion is not the default operation of the printf statement, but it is correct, as follows:
printf("%d\n ",(int)a);
Otherwise, if you write printf("%d\n ",a); Printf does not perform forced data type conversion.
The problem of forced type conversion in C language is 1, assuming that float x = 0.0int y = 5;; Of course, this assumption is unreasonable and is not recommended for real programming.
Then, x = (float) y; This is a forced type conversion in C. There is no compilation error, but it depends on whether you have any logical errors.
Context of code
2, as for num (float);
I can tell you that this is a function and there is only one parameter, and the parameter type is float.
For forced type conversion, the right value (= right part) of an expression is always (manually) converted to a type that matches the left value (= left part).
The question about C language compulsion cannot be explained.
What compiler are you?
I use g.
validation procedures
int main()
{
volatile int a = 0;
Fluctuation b = 0.14;
a =(int)(b * 1000);
printf("%d\n ",a);
}
output
140
The problem of forced conversion in C language is "rounding", not "rounding", that is, taking the largest (absolute) integer not greater than the forced data!
A problem of mandatory conversion of C language, the compilation environment you use may be TC! Such a compiler defaults to two bytes, namely 16 binary digits. For signed int, the highest bit of the binary number represents the symbol, "0" is positive and "1" is negative.
Arithmetic exists in memory in the form of its complement, and the positive complement is itself. For example, the binary number10101is expressed in memory as 000000000000010/,the first one. The complement of a negative number is its complement+1, such as-100 1 10. First rewrite it as-0000000000010065438, (regardless of its highest order, look at the data bits first, That is to say, the last digit is1111111. The complement of 5438+0010-110 is stored in the computer memory in the form of1165438.
For (int) m = 1 00000000000, because it is seventeen digits, the highest digit1is omitted when it is stored, and it is stored in memory as 0 000000000000, which is a positive number 0.
Look at (int) n =11111165438.
In order to avoid this situation or get a wider range of integers, it is recommended to use VC compiler, because its plastic data takes up 4 bytes in memory.
The problem of C++ type coercion is that each Chinese character takes up 2 bytes, and of course, the symbols input by Chinese input method also take up 2 bytes, and the ASCII value stored in each byte (where the ASCII value is inaccurate) is negative. The program you wrote is that as long as there is something in the input stream, it will loop once, that is, read it in and output it. The two ASCII values of are -93 and -92 respectively. Read and output -93 for the first time, and then read and output -92 for the second time to cin, so there are two values.
Forced conversion in C language int open ()
FILE *fopen()
You are confused.