scanf()跳过变量
在C中,使用带参数的scanf()
, scanf("%d %*d", &a, &b)
行为不同。 它仅为一个变量而不是两个变量输入值!
请解释一下!
scanf("%d %*d", &a, &b);
*
基本上表示忽略说明符(读取整数但未分配)。
man scanf的报价:
* Suppresses assignment. The conversion that follows occurs as usual, but no pointer is used; the result of the conversion is simply discarded.
星号(*)表示将读取格式的值,但不会写入变量。 scanf
不希望在其参数列表中为该值指定变量指针。 你应该写:
scanf("%d %*d",&a);
http://en.wikipedia.org/wiki/Scanf#Format_string_specifications
百分比符号后面的可选星号(*)表示此格式说明符读取的数据不存储在变量中。