C - Exception when using _int16 [duplicate]

2019-08-07 17:11发布

问题:

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:

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

scanf("%d", &a);

with

scanf("%hd", &a);