1. I canโt understand a couple of things. First, how to add a signed and unsigned number, enter the input result in an unsigned type?
This is determined by integer shares and an integer rank conversion.
6.3.1.8 p1: Otherwise, if an operand with an unsigned integer type has a rank greater than or equal to the ranks of the type of another operand, then the operand with an integer type with a sign is converted to the type of the unsigned operand of an integer type.
In this case, unsigned has a higher rank than int, so int is assigned unsigned.
Converting int (-2) to unsigned is done as described:
6.3.1.3 p2: Otherwise, if the new type is unsigned, the value is converted by repeatedly adding or subtracting one greater than the maximum value that can be represented in the new type until the value is in the range of the new type
2. If the result is really 0xFFFFFFFF of unsigned type, why in a 32-bit system, adding it with ptr, will it be interpreted as ptr-1, given that the number is actually unsigned, and the leading 1 should not mean a sign?
This behavior is undefined and cannot be relied on, since C does not define pointer arithmetic overflows.
6.5.6 p8: If both the operand and the result pointers point to the elements of the same array object or one after the last element of the array object, the evaluation should not lead to overflow; otherwise, the behavior is undefined.
3. Secondly, why is the result different from a 64-bit system?
(This assumes (like the image) that int and unsigned have 4 bytes.)
The result of A and B is the same as described in 1., then this result is added to the pointer. Since the pointer has 8 bytes and it is assumed that the addition does not overflow (anyway, if ptr had a large address, giving the same undefined behavior as in 2.), the result is the address.
This behavior is undefined because the pointer points outside the bounds of the array.