如何正确运行程序?每当我运行该程序时,它说.exe停止工作。请帮忙 [英] How do I run the programme properly? Whenever I run the programme, it says .exe stopped working. Please help

查看:78
本文介绍了如何正确运行程序?每当我运行该程序时,它说.exe停止工作。请帮忙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
#include<conio.h>
int main()
{
	int a,b,c;
	
	printf("\nEnter the value of a : ");
	scanf("%d",a);
	
	printf("\nEnter the value of b : ");
	scanf("%d",b);
	
	printf("\nEnter the value of c : ");
	scanf("%d",c);
	
    if(a>b)
	{
		if(a>c)
		printf("\n%d is the largest number",a);
		else
		printf("\n%d is the largest number",c);
	}
	else
	{
		if(b>c)
		printf("\n%d is the largest number",b);
		else
		printf("\n%d is the largest number",c);
	}
}





我的尝试:



当我运行程序时,输入a的值后,它说.exe停止工作。

请帮助我。



What I have tried:

When i run the programme,, after entering value of a, it says, .exe stopped working.
Please help me.

推荐答案

scanf需要您要存储值的变量的地址,而不是内容。所以当你这样写:

scanf requires addresses of the variables you want to store teh values in, not teh content. So when you write this:
int a,b,c;
...
scanf("%d",a);

您传递一个随机值(因为您还没有将任何内容分配给 a )作为您希望结果放入的地址。所以它确实如此。 ,发现它不存在,你的应用程序崩溃。



当你用C或C ++调用函数时,所有参数都是按值传递的,而不是通过引用传递的 - 制作内容的副本,然后传递内容,而不是说出内容的来源。如果你考虑一下,那是个好主意:

You are passing a random value (since you haven't allocated anything to a yet) as the address you want the result placed in. So it does, finds it doesn't exist, and your app crashes.

When you call a function in C or C++, all parameters are passed by value, not by reference - a copy of the content is made and that is passed rather than something which says where it came from. If you think about it, that is a damn good idea:

void DoSomething(int i)
   {
   i = 1 + 1;
   }

当你这样称呼它时很好:

Is fine when you call it like this:

int val = 666;
DoSomething(val);

Eitehr方式,但如果你这样称呼:

Eitehr way, but if you call it like this:

DoSomething(666);

然后任何按引用传递调用都会给你带来真正的问题,因为常数的值必须改变!



尝试传递 a 的地址而不是值:

Then any "pass by reference" call will give you real problems as the value of a constant number would have to change!

Try passing the address of a instead of the value:

scanf("%d",&a);

and don'忘记 b c

And don't forget b and c either!


这篇关于如何正确运行程序?每当我运行该程序时,它说.exe停止工作。请帮忙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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