当我使用两个扫描 #define("%d" ,&2)时,输入 1 后得到输出 4



该程序尝试从用户那里获取输入并将其存储在名为 2 的宏中,但是当我打印宏时,我得到 1 作为输出....为什么?

#include <stdio.h>
//declares two 
int two;
//Takes input to store it in two 
#define two scanf("%d",&two)
int main() 
{
      printf("%dn",two);
 return 0;
}

您看到的是 scanf 返回的值。返回值是 scanf 成功填充的项目数(在本例中为 1 个项目(。请参阅此参考: http://www.cplusplus.com/reference/cstdio/scanf/

最新更新