scanf 格式说明符中的星号是什么意思? [英] What does an asterisk in a scanf format specifier mean?
本文介绍了scanf 格式说明符中的星号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我偶然发现了这段代码,但我无法弄清楚它的目的是什么,或者它是如何工作的:
So I stumbled across this code and I haven't been able to figure out what the purpose of it is, or how it works:
int word_count;
scanf("%d%*c", &word_count);
我的第一个想法是 %*d
引用了一个 char
指针或禁止 word_count
获取 char
变量.
My first thought was that %*d
was referencing a char
pointer or disallowing word_count
from taking char
variables.
有人可以解释一下吗?
推荐答案
*c
意思是,一个字符会被读取但不会被赋值,例如对于输入30a"它将 30 分配给 word_count
,但 'a' 将被忽略.
*c
means, that a char will be read but won't be assigned, for example for the input "30a" it will assign 30 to word_count
, but 'a' will be ignored.
这篇关于scanf 格式说明符中的星号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文