Friends can you please tell me the exact way of how the assigned value and output aren't equal? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Friends can you please tell me the exact way of how the assigned value and output aren't equal?

https://code.sololearn.com/c7rKvl02kdZH/?ref=app

12th Feb 2023, 5:20 PM
Keerthana.S
Keerthana.S - avatar
3 Answers
+ 5
short type takes only 2 bytes. Unsigned values can't hold negative values. So you can only store values between 0 to 65535. So your int value -3755768, will be converted to unsigned short int value to store in compatible type.... Generally, 2's compliment form of number is the converted value.. So the -3755768 number 2's compliment form is 45320 in 2 bytes range. overflown bits are ignored..
12th Feb 2023, 7:56 PM
Jayakrishna 🇮🇳
+ 3
Keerthana.S What are you trying to do? Your attempting to assign a value of ‘minus 3755768’ to an unsigned short. Unsigned (clue in the name) doesn’t include the sign bit. Also the range for a unsigned short is 0 to 65,535, much less than needed. Implicit type conversion happening, then your print format specifiers are for an unsigned and signed int 🤔 To store -3755768 correctly you would want to be using a signed int. The correct format specifier with print function would be %d. The assigned value and output value differ because of the conversion - if correctly assigned types the output is the same: int a = -3755768; printf("%d", a);
12th Feb 2023, 5:57 PM
DavX
DavX - avatar
0
if your are on js its object != value ...i hope this helps
12th Feb 2023, 6:00 PM
Dagmawi
Dagmawi - avatar