Please clear the following for me:
- What happens when we store a signed integer in an unsigned type?
- Is it not necessary to mention ‘int’ when we are using data type modifiers like ‘unsigned’,‘long’ etc?
Please clear the following for me:
The output of this question depends upon the datamodifiers:
Let’s say you assign -2 to an unsigned integer, then for 32 bits int it will results in 2^32 - 2
It would be 2^16 - 2 for short unsigned integer
Similarly, for long long unsigned integer it would be 2^64 - 2
And for signed integer, it will be -2.
Yes, as an unsigned type cannot store the negative sign, thus the compiler converts it into an above mentioned unsigned representation.
Nope, it’s not a necessity to mention “int” as these datatype modifiers are for int only.
Hope, this would help.
Give a like, if you are satisfied.