0x0f65f508 处的未处理异常 (msvcr100d.dll)

Unhandled exception at 0x0f65f508 (msvcr100d.dll)

所以我一直在做一个项目,它只是一个命令行程序。 我 运行 遇到的问题是当我想创建一个计算器时。代码如下所示:

int calculator()
{
char oper[1];
double x, y;
x = 1;
y = 1;
printf("Starting calculator...\n\n");
printf("Input an operator you want to execute: ");
gets(oper);

if (strncmp(oper, "+", 1) == 0)
{
    printf("\ncalculator works like this x + y =\n");
    printf("input x value:\n");
    scanf("%lf",x);
    printf("input y value:\n");
    scanf("%lf",y);
    printf("%.1lf + %.1lf = %.1lf\n",x, y, x+y);

}
else if (strncmp(oper, "-", 1) == 0)
{
    printf("\ncalculator works like this x - y =\n");
    printf("input x value:\n");
    scanf("%lf",x);
    printf("input y value:\n");
    scanf("%lf",y);
    printf("%.1lf + %.1lf = %.1lf\n",x, y, x+y);


}
else if (strncmp(oper, "*", 1) == 0)
{
    printf("\ncalculator works like this x * y =\n");
    printf("input x value:\n");
    scanf("%lf",x);
    printf("input y value:\n");
    scanf("%lf",y);
    printf("%.1lf + %.1lf = %.1lf\n",x, y, x+y);

}
else if (strncmp(oper, "/", 1) == 0)
{
    printf("\ncalculator works like this x / y =\n");
    printf("input x value:\n");
    scanf("%lf",x);
    printf("input y value:\n");
    scanf("%lf",y);
    printf("%.1lf + %.1lf = %.1lf\n",x, y, x+y);
}
else
{
    printf("Incorrect operator, please try again!\n");
}
}

根据一些示例和教程,它应该可以正常工作,而且确实如此。 但是问题是在 运行 代码之后开始的。在插入 x 值之前,它工作正常。紧接着错误出现:

program.exe 中 0x0f74f508 (msvcr100d.dll) 的未处理异常:0xC0000005:访问冲突写入位置 0x00000000。

我见过类似的问题,但 none 确实给出了解决方法。感谢您的帮助!

尝试用 scanf("%lf",&x);

替换 scanf("%lf",x);