Lines
scanf("%s", &str1);
and
scanf("%s", &str2);
really wrong (at least both contain a typo). They should be written as
scanf("%s", str1);
and
scanf("%s", str2);
Arrays and array expressions are special in C. Unless it is a sizeof operand of either unary & operators or a string literal used to initialize another array in a declaration, an expression of the type "N is an array of T elements" will be converted (decay) to an expression of type " pointer to T ", and the value of the expression will be the address of the first element of the array.
The str1 expression is of type "20-element char array". If str1 appears in a context where it is not an operand of the sizeof or unary & operators, it will be converted to an expression of type "pointer to char ", and the value of the expression will be the same as &str1[0] ; therefore, you do not need to use & to read strings, as an array expression will be treated as a pointer. However, when it is the operand of the unary operator & , the conversion rule is not applied, and the expression type &str1 is a "pointer to a 20-element char array" ( char (*)[20] ). Hence your warning.
The str1 and &str1 will be the same (the address of the first array of elements matches the address of the array), but the types of expressions are different and have a type value. A pointer to a char will be handled differently than a pointer to a char array.
90% of C books and textbooks are shit; be very skeptical of any C reference that is not the actual standard. Harbison and Steele C: The Reference Guide (currently the 5th edition) has been my link to the link since the late 80s, but even it has minor errors.
source share