Short int不接受该值

nsi*_*son 2 c compiler-construction

给予以下程序的输入是

10 10

10 10

但输出是

0 20

为什么?

/* scanf example */
#include <stdio.h>


int main ()
{
    short int a, b, c, d, e, f;
    a=b=c=d=e=f=0;
    scanf("%d %d",&a,&b);
    scanf("%d %d",&e,&d);
    c=a+b;
    f=d+e;

    printf("%d %d\n",c,f);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

CB *_*ley 8

正确的scanf格式说明符short int%hd,不是普通的%d.您遇到了未定义行为的结果.