Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I don't undersand why the result is 44 ?

What I have tried:

Objective-C
#include <stdio.h>

int main(){
unsign char a,b,c;
a=100;
b=200;
c=a+b;
printf("%d", c);

}
Posted
Updated 18-Apr-16 7:29am
Comments
Sergey Alexandrovich Kryukov 18-Apr-16 13:49pm    
42. :-)
—SA
Philippe Mori 18-Apr-16 20:44pm    
Stuff you should have learn at school...

1 solution

A char holds an ASCII character code, from 0 to 256 (1 byte). Adding up 100 and 200 results in 300, which is too big for one byte, so it overflows and will store 300 % 256 = 44 in c.
 
Share this answer
 
Comments
Laurentiu Bobora 18-Apr-16 13:43pm    
Thanks !
Sergey Alexandrovich Kryukov 18-Apr-16 13:50pm    
Ha-ha, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900