This section continues with the basic knowledge points of the C language.
scanf function: Used to receive data entered by the user.
Syntax: scanf ("Format control", address list);
Address should be used to fetch the address character:& (shift+7)
For example: int num = 0; CSANF ("%d", &num);p rintf ("num =%d \ n", num);
Note: The type of data that is required to be entered before the format control, the address list must only be placed in the corresponding type variable address. When entering a value, you can specify the delimiter for the input value.
You can also use carriage return by default.
Features of scanf:
It is a block-type function.
For example: printf ("Please enter: \ n");
int num;
scanf ("%d" &num);
printf ("Oh, you entered%d", num);
Enter multiple values at once: int num; float NUM1; (You can enter n times, n= the number of formatting controls)
scanf ("%d%f", &NUM,&NUM1);
Note: The order can not be chaotic, if you do not want to use a blank line input, you can specify other symbols, but the input must follow this symbol, otherwise it will be abnormal (after the variable is not connected to the value); If you want to add text in the scanf, enter it must follow the format in the scanf to enter When using scanf, it is best not to receive an arbitrary numeric type (integer, real), receive a char type, and if you want to receive a char type, be sure to precede the scanf format control with a space. If scanf is going to receive a number, no matter how many spaces and carriage returns you enter, it will not stop you, and if scanf is going to receive an int type and you enter a decimal, it will only intercept the integer portion of the decimal. If you receive a number and you enter a character, the input is stopped, but the value you entered is not saved.
Operating principle of scanf:
The scanf is used to receive input from the user, but the user's input is not given directly to the variable, but the buffer is present. The steps are as follows:
1, receive input, will first go to the buffer inside to look for, see if the buffer is appropriate value, if there is, then directly stop the input, and then assign the value of this to the variable. If not, always let you input, until there is a suitable so far.
Introduction to the basic knowledge of C language Learning (III.)