The function call scanf ("%d", &weight) contains two parameters: "%d" and &weight. c Use commas to separate multiple parameters in a function call;
However, the printf () and scanf () functions are special and the number of functions is not controlled.
For example, we can call the printf () function with 1, 2, 3, or even 4 parameters. The program needs to know the number of parameters in order to work properly, and the two functions determine the number of subsequent arguments by the first argument, by using each specifier in the first argument string corresponding to one of the following parameters.
The following statement contains two format specifiers:%d and%d
printf ("%d cats aate%d cans of tuna \ n", cats, cans);
Two format specifiers tell the program that there are two parameters; there are 2: cats and cans;
You must ensure that the number of format specifiers is the same as the number of arguments that follow. Now C checks whether the function call uses the correct number and type of parameters through a function prototype mechanism;
However, this does not work for the printf () and scanf () functions because their number of parameters is variable;
int scanf (const char *format, ...); The scanf () function declaration in man;
scanf (), printf () function in C language