我变量'信用'变得荒谬

时间:2016-12-09 18:30:20

标签: c variables

#include <stdio.h>
int main (void)
{
int hist,geo,phy,chem,bio;

int credits=0;


printf("Enter marks in history : ");
scanf("%d",&hist);

if(hist>40)
credits =10;
else
printf("No credits awarded for history");
printf("Credits obtained is %d",&credits);




return(0);

}

当我运行代码时,我得到变量'Credits'的值为230586。请帮忙。我是C的初学者

1 个答案:

答案 0 :(得分:1)

&x就像问一个问题“变量x的地址是什么?” ,这就是为什么你得到这个奇怪的数字。要打印变量值,请将credits而不是&credits传递给printf函数。

printf("Credits obtained is %d", credits);