本文介绍了scanf() 跳过变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 C 中,将 scanf() 与参数一起使用,scanf("%d %*d", &a, &b) 的作用不同.它只为一个变量而不是两个变量输入值!
请解释一下!
scanf("%d %*d", &a, &b); 解决方案* 基本上意味着忽略说明符(整数被读取,但未分配).
引自man scanf:
* 禁止赋值.接下来的转换发生为通常,但没有使用指针;转换的结果是干脆丢弃了.In C, using scanf() with the parameters, scanf("%d %*d", &a, &b) acts differently. It enters value for just one variable not two!
Please explain this!
scanf("%d %*d", &a, &b);
解决方案
The * basically means the specifier is ignored (integer is read, but not assigned).
Quotation from 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() 跳过变量
发布评论