为什么减去人数C测试结果“0”的字符重新presenting? [英] Why does subtracting '0' in C result in the number that the char is representing?

查看:123
本文介绍了为什么减去人数C测试结果“0”的字符重新presenting?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释为什么这个工程?

Can someone explain why this works?

char c = '9';
int x = (int)(c - '0');

为什么减去一个char结果的ASCII code'0'是该字符重新presenting多少?

Why does subtracting '0' from an ascii code of a char result the number that that char is representing?

推荐答案

由于炭都重新由若干'0'psented $ P $是第一次这一切。

Because the char are all represented by a number and '0' is the first of them all.

放在桌子的下面你看到的:

'0' => 48
'1' => 49


'9' => 57.

结果:'9' - 0 )= (57 - 48)= 9

As a result: ('9' - '0') = (57 − 48) = 9


来源: http://www.asciitable.com

这篇关于为什么减去人数C测试结果“0”的字符重新presenting?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆