C - Exception when using _int16 [duplicate]

2019-08-07 16:59发布

Possible Duplicate:
Correct way to use scanf / printf (and family) with fixed size types?

I have written the following program in Visual Studio:

Upon running the program and exiting, I get the error message "stack around variable b was corrupted". If I replace _int 16 with int, no exception is raised. How can I solve this problem please? I have to use _int16 since I want to simulate an integer overflow. Thanks :)

1条回答
The star\"
2楼-- · 2019-08-07 17:25

As pointed out in the comments, the solution is to replace

scanf("%d", &a);

with

scanf("%hd", &a);
查看更多
登录 后发表回答