As you can see from the code snippet below, I have declared one char
variable and one int
variable. When the code gets compiled, it must identify the data types of variables str
and i
.
Why do I need to tell again during scanning my variable that it's a string or integer variable by specifying %s
or %d
to scanf
? Isn't the compiler mature enough to identify that when I declared my variables?
#include <stdio.h>
int main ()
{
char str [80];
int i;
printf ("Enter your family name: ");
scanf ("%s",str);
printf ("Enter your age: ");
scanf ("%d",&i);
return 0;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…