悝跞 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日

悬赏问题

  • ¥15 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败