0

Any body explain the theory of this code?

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

16th Apr 2022, 4:43 PM
Sachin Pradhan
Sachin Pradhan - avatar
1 Réponse
+ 3
Certainly. int main() { char c=255; A char is a one byte sized data type. That is 8 bits. The largest number is can hold as an unsigned number is 2^8-1 = 255. After that it starts from zero. To make things short, an unsigned byte holds a value modulo 256. Now, in some cases, a char is signed, as in this case. But that shall not concern us, because the final result is positive and less than 128. And for that range, signed and unsigned char coincide. c=c+10; Here we add 10. But because of the 8bit type, the result is modulo 256. Now, 255+10 = 265 is congruent 9 modulo 256. Hence, printf ("%d",c); outputs 9. The format specifier indicates an integer type, not a char. But, in C, a char is an integral type and can implicitly be enlarged to an int. return 0; This is your standard "everything went well" goodbye formula. The program ends here (exits the main function). }
16th Apr 2022, 5:08 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar