I’m just wondering why n = 0 here?
char c = 0xff;
int n = c+1;
cout << n << endl;
system("pause");
1) c = 0xff
2) 0xff + 1 = 0x100.
Could you explain?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming an unsigned
chartype,0xffwould give the decimal value 255. Add one to that and you get 256, or0x100or 256. This would be printed out as100if you had manipulatedstd::coutto print in hex withstd::cout << std::hex;Assuming an 8-bit signed
char,0xffwould overflow, giving -1. Add 1 to that and you would get 0.