C - Exception when using _int16 [duplicate]

别来无恙 提交于 2019-12-13 01:25:55

问题


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);


来源:https://stackoverflow.com/questions/12936521/c-exception-when-using-int16

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!