//For the operation of the self-increment and decrement operator is worth studying, be careful to be pits.
1#include <stdio.h>2 intMainvoid){3 intI=5, j=5, P,q;4P= (i++) + (i++) + (i++);5Q= (++J) + (++J) + (+ +)j);6printf"p=%d,q=%d,i=%d,j=%d", p,q,i,j);7 return 0;8}
The results of his operation:
Q= (++J) + (++J) + (++J) is supposed to be 21 Ah!
Original: For q= (++J) + (++J) + (++J), first calculate (++j) + (++J), because is "pre-plus", to calculate two times ++j, at this time j=7, then add, equivalent to 7+7, the result is 14; then the 14+ (++J), the equivalent of 14+8, the result is 22.
This is the Fedora Platform feature, other platforms can self-test.
Type conversions
If the data types are different on either side of the assignment operator, the system will automatically convert the type to the right of the assignment number to the left type. Specific provisions are as follows:
- The real type gives the integer type, rounding off the fractional part.
- The integer is given a true type, the value is constant, but it is stored as a floating point, which increases the fractional part (the value of the decimal portion is 0).
- The character type is given an integer, because the character type is one byte, and the integer type is two bytes, so the ASCII value of the character is placed in the low eight bits of the integer, and the height eight bits is 0. The integer type is given a character, and only the lower eight bits are given the character amount.
Compound assignment operators
The addition of the two-mesh operator before the assignment "=" can form a compound assignment. such as + =,-=, *=,/=,%=, <<=, >>=, &=, ^=, |=.
Attention problems of C-language operators