0

The program shuts down after I enter the first input

#include<stdio.h>
int main(void)
{
    int biology,chemistry;
    printf("\nEnter marks for maths");
    scanf("%d",biology);
    printf("\nEnter marks for tech1");
    scanf("%d",chemistry);
    return(0);
}
Vinay Shukla
  • 1,818
  • 13
  • 41
user3934169
  • 13
  • 1
  • 1
  • 5

2 Answers2

5

C function parameters are always "pass-by-value", which means that the function scanf only sees a copy of the current value of whatever you specify as the argument expression.

If you passed biology, then it would only see an uninitialized value. On the other hand &biology is a pointer value that refers to the variable i.e scanf can use this to modify biology.

The scanfwould need to be modified as follows

scanf("%d", &biology);
scanf("%d", &chemistry);

To understand this in detail read Why does scanf require &

Community
  • 1
  • 1
Vinay Shukla
  • 1,818
  • 13
  • 41
1

You are passing incorrect arguments to scanf() calls. You must pass the address of the variables (see scanf()'s documentation) to match %d format.

scanf("%d", &biology);
...
scanf("%d", &chemistry);

You should also check the return code to see if the scanf() calls succeeded.

P.P
  • 117,907
  • 20
  • 175
  • 238