Is getchar() equivalent to scanf(“%c”) and putchar() equivalent to printf(“%c”)?

前端 未结 2 797
遥遥无期
遥遥无期 2020-12-29 14:55

Is a = getchar() equivalent to scanf(\"%c\",&a);?

Is putchar(a) equivalent to printf(\"%c\",a); where a

2条回答
  •  长发绾君心
    2020-12-29 15:42

    They do the same thing here. However, if you know you are just doing characters then getchar and putchar will be more efficient, since the printf and scanf variants will have to parse the string each time to determine how to process your request. Plus, they may be called in a lower level library meaning you may not have to have the printf/scanf linked if they are not needed elsewhere.

提交回复
热议问题