+ 1

What is the output of this code?

Most importantly, HOW this output came as 64! I am not able to imagine how this program works! Please help! https://code.sololearn.com/ch6LZf0LY031/?ref=app

1st Jul 2019, 6:06 AM
Vijay Sapkal
Vijay Sapkal - avatar
4 Answers
+ 6
To explain it in a easy way that's why bits are viewed from the point of view of a char type when you use 'char ptr' , like you are using " char lens " to see a number... , now you can see only the first 8 bits and the value becomes 64, the 10th bit has the remaining 256... This code shows what happens.. hope it helps. https://code.sololearn.com/czCX3QAN90Cp/?ref=app
1st Jul 2019, 9:43 PM
AZTECCO
AZTECCO - avatar
+ 3
signed char range from - 127 to 128, if we assign value more than the range, a cyclic operation will be perform due to over flow, where the remaining value after 128 will begin from go though the circle again and continue until all the value is exusted, the is a kind of formula to calculate it which goes by 320%256 if the value is less than 127 thats the ans and if it's greater hence you will subtract the value from 256, 320%256 - - > 64
1st Jul 2019, 5:09 PM
āœ³AsterisKāœ³
āœ³AsterisKāœ³ - avatar
+ 2
Char overflow.. If you try replacing 320 by any number below 127 and > - 128, it will display it. But a char doesn't have the same memory size than an int. A char is stored on 1 byte whilst an int is stored on 4bytes. Hence, when you cast an int to a char, some data will be lost
1st Jul 2019, 6:38 AM
Drax
Drax - avatar
+ 2
Gordie [#observer_status_only] you shouldn't have removed it, other users too might have similar issues too
1st Jul 2019, 5:13 PM
āœ³AsterisKāœ³
āœ³AsterisKāœ³ - avatar