-6

I was trying to get into c programming, but in a question a get stuck, please explain this.

 int main()
{
 char c = 255;
 c=c+10;
 printf("%d",c);
 return 0;
 }

the output it gave is

> 9

kindly explain this to me.

heeat
  • 128
  • 2
  • 9

1 Answers1

4

The maximum value of a char is 255.

By adding 10 to that number you get 265.

Because that value is not a suitable value for a char it will do 265 % 256 resulting 9

That's why your result is 9

Darkpingouin
  • 196
  • 12