首页 文章

扫描long unsigned int的格式说明符

提问于
浏览
10

我试图使用此代码片段将两个变量作为输入: -

unsigned int i;

unsigned long int j;

scanf("%u",i);

scanf("%lu",j);

但这引起了以下警告: -

警告:格式'%u'需要'unsigned int *'类型的参数,但参数2的类型为'unsigned int'[-Wformat]警告:格式'%lu'需要类型'long unsigned int *'的参数,但参数2有'long unsigned int'类型[-Wformat]任何人都可以向我解释这里发生了什么?

1 回答

  • 22

    你需要添加一个前导 & ,因为 scanf 指向输出参数 . 否则,它无法写入它们 .

    scanf("%lu", &i);
    

相关问题