Even experienced developers fall victims to type conversion intricacies in C. Consider the following snippet.
int32_t b=-55;
std::cout << (a+b) << std::endl;
Running these lines produces console output of 4294967248 which certainly isn’t an expected result of the sum. The “paradox” is a result of how implicit type conversion works in C++. The standard interpretation of unsigned (at least in most compilers) is a 32-bit unsigned integer. When a signed and an unsigned integers of the same size are added together the compiler implicitly treats the result as unsigned. Thus the output.
However let us experiment with variables of different sizes as in the following example and this time we spell out their sizes to avoid any confusion.
int64_t b=-55;
std::cout << (a+b) << std::endl;
It may be a shock to some of us that this snippet spits out the expected -48. Here size of the larger variable takes precedence over signedness.