为什么参数为isdigit整数? [英] Why is parameter to isdigit integer?

查看:45
本文介绍了为什么参数为isdigit整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

函数 std :: isdigit 是:

  int isdigit(int ch);

返回值(如果字符是数字字符,则为非零值,否则为零).闻起来就像该函数是从C继承的,但是即使那样也不能解释为什么参数类型为 int 而不是 char 同时...

The return (Non-zero value if the character is a numeric character, zero otherwise.) smells like the function was inherited from C, but even that does not explain why the parameter type is int not char while at the same time...

如果ch的值不能表示为,则行为不确定unsigned char,不等于EOF.

The behavior is undefined if the value of ch is not representable as unsigned char and is not equal to EOF.

是否有技术上的原因为何数字采用 int 而不是 char ?

Is there any technical reason why isdigitstakes an int not a char?

推荐答案

原因是允许 EOF 作为输入.并且 EOF 是(来自此处):

The reaons is to allow EOF as input. And EOF is (from here):

int类型和负值的EOF整数常量表达式

EOF integer constant expression of type int and negative value

这篇关于为什么参数为isdigit整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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