scanf() 跳过变量 [英] scanf() skip variable

查看:48
本文介绍了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() 跳过变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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