C - 使用_int16时的异常 [英] C - Exception when using _int16

查看:207
本文介绍了C - 使用_int16时的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

使用具有固定大小类型的scanf / printf(和family)的正确方法?

我在Visual Studio中编写了以下程序:

I have written the following program in Visual Studio:

运行程序和退出,我收到错误消息堆栈变量b已损坏。如果我用int替换_int 16,则不会引发异常。请问如何解决这个问题?我必须使用_int16,因为我想模拟一个整数溢出。感谢:)

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

推荐答案

正如在评论中指出的那样,解决方案是替换

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

scanf("%d", &a);

scanf("%hd", &a);

这篇关于C - 使用_int16时的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆