是的getchar(),相当于scanf函数(QUOT;%C")和的putchar()相当于对printf(QUOT;%C")? [英] Is getchar() equivalent to scanf("%c") and putchar() equivalent to printf("%c")?

查看:175
本文介绍了是的getchar(),相当于scanf函数(QUOT;%C")和的putchar()相当于对printf(QUOT;%C")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A =的getchar()等同于 scanf函数(%C,&安培; A);

的putchar(一)等同于的printf(%C,A); ,其中 A 字符变量?

Is putchar(a) equivalent to printf("%c",a); where a is a char variable?

推荐答案

一般来说是的,他们是相同的。

Generally speaking yes they are the same.

但他们不是在几个挑剔的方式。功能的getchar 键入返回 INT ,而不是字符 。这样做是让的getchar 既能所有可能的字符值,且还错误codeS。

But they are not in a few nitpicky ways. The function getchar is typed to return int and not char. This is done so that getchar can both all possible char values and additionally error codes.

因此​​,虽然下面的愉快编译大多数编译器你基本上是截断走一条错误消息

So while the following happily compiles in most compilers you are essentially truncating away an error message

char c = getchar();

功能 scanf函数,虽然,允许你使用一个字符直接键入并分离出错误code成返回值。

The function scanf, though, allows you to use a char type directly and separates out the error code into the return value.

这篇关于是的getchar(),相当于scanf函数(QUOT;%C")和的putchar()相当于对printf(QUOT;%C")?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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