Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does printing 577 with %c output "A"?

#include<stdio.h>
int main()
{
  int i = 577;
  printf("%c",i);
  return 0;
}

After compiling, its giving output "A". Can anyone explain how i'm getting this?

like image 538
divine ocean Avatar asked Oct 26 '25 19:10

divine ocean


1 Answers

%c will only accept values up to 255 included, then it will start from 0 again !

577 % 256 = 65; // (char code for 'A')

like image 69
axelduch Avatar answered Oct 29 '25 09:10

axelduch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!