How to solve the quiz of fundamental 1.0 Question no.5

unsigned A = -25;
cout<<A;

//Output?? and How?

Hello @jatinkumarjk2001,

The output of this question depends upon the data modifiers:

  1. 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.

  2. As an unsigned type cannot store the negative sign, thus the compiler converts it into an above mentioned unsigned representation.

  3. It’s not a necessity to mention “int” as these datatype modifiers are for int only.

So, using point 1, the output of your code would be:
for 64 bits int: 2^64 - 25

Hope, this would help.
Give a like, if you are satisfied.

but the answer is only 2^32

Hey @jatinkumarjk2001,

2^32 is for 32 bit int.
But, it should be 2^32 -25
Can you share your code?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like