【发布时间】:2016-07-16 07:59:14
【问题描述】:
我的代码:-
#include<stdio.h>
#include<conio.h>
void main(){
int a,b,c;
printf("Enter the 1st number:");
scanf("%d",a);
printf("Enter the 2nd number:");
scanf("%d",b);
c=a*b;
printf("The value of %d * %d is %d",a,b,c);
getch();
}
现在当我在 Turbo C++ 中执行这个程序时,输出如下:-
Enter the 1st number:10
Enter the 2nd number:10
The value of 1308 * 1320 is 22625
为什么会这样?
【问题讨论】:
-
你还没有传递 scanf 指针。在 scanf 行的“a”和“b”前面添加一个 & 符号。您的标题表明您已经知道这是问题所在。
-
对于所有
scanf()语句,@EJP、scanf("%d",a);应该是scanf("%d",&a);等等。 -
是的@Borealid我一开始就知道&符号是问题,但我想知道&符号的作用以及没有&符号系统采用的值如何变为1308和1320对于'a'和' b'分别?很抱歉没有在问题本身中提及这一点。也许我应该在发布之前检查我的问题的写作。
标签: c