悝跞 2022-02-04 11:25 采纳率: 100%
浏览 34
已结题

scanf引用第二个值跳转后第三个哪来的

#include"stdio.h"
int main()
{int a,b,c,d;
scanf("%2d%*3d%2d",&a,&b,&c);
printf("%d,%d,%d",a,b,c);}
输入:123456789
输出:12 67 127

  • 写回答

1条回答 默认 最新

  • _GX_ 2022-02-04 15:14
    关注

    %*3d表示忽略域宽为3个字符的整型,因此你输入的字符串中345是被忽略掉了,再接下来%2d读入67是赋给b的,c没有被赋值,其值是未初始化的随机值。

    FROM https://en.cppreference.com/w/c/io/fscanf

    conversion specifications. Each conversion specification has the following format:

    • introductory % character
    • (optional) assignment-suppressing character *. If this option is present, the function does not assign the result of the conversion to any receiving argument.
    • (optional) integer number (greater than zero) that specifies maximum field width, that is, the maximum number of characters that the function is allowed to consume when doing the conversion specified by the current conversion specification. Note that %s and %[ may lead to buffer overflow if the width is not provided.
    • (optional) length modifier that specifies the size of the receiving argument, that is, the actual destination type. This affects the conversion accuracy and overflow rules. The default destination type is different for each conversion type (see table below).
    • conversion format specifier
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 2月20日
  • 已采纳回答 2月12日
  • 创建了问题 2月4日

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?