Problem with variable input in C program
I have a problem with the real variable. i can put age on the console instead of 20 in the course of the variables.
Code:
# include <stdio.h>
# include <stdlib.h>
int main (int arg, char * argv [])
(
long age = 0;
printf ( "How old are you?");
scanf ( "% ld", & age);
printf ( "you really ld% year \ n", & age);
system ( "PAUSE");
return 0;
)
could you help me to solve this problem please?
Re: Problem with variable input in C program
do not pass the address instead of the value of your variable
Code:
int age = 0;
printf (what is your age:);
scanf ( "% d", & age);
printf ( "I% d years", age);
Re: Problem with variable input in C program
in Line 9, we should not put the ampersand to 'age' as% printf expects a value, not an address. This is what your declaration does not boot you if your variable are not declared.