# Include "stdio. H"
Void main ()
{
Char string [] = "C Language ";
Char * P;
P = string;
Printf ("% s \ n", string); // is the string address name? How to output a string?
Printf ("% s \ n", P); // P is also the address name. How can I output a string?
}
A: % s is a string of course, and % d is the address. Depends on the output format.
Q: Why is printf ("% s", * P); incorrect ??
A: % s is of course a string. % d is the address.
("% S", * P), * P is the value of the first address of the string, that is, 'c'. It is not a string and % s is incorrect.
Printf ("% C", * P) will not report an error.
The array name is equivalent to a pointer pointing to the first part of the array, so ....
P is a pointer pointing to the first address of the array.
Because % s is to output a string, the required parameter is the first address of the string ending with null, while % c Outputs a character, so * P is required.
Example 1:
Printf ("% C \ n", string [6]);
Printf ("% C \ n", P [6]);
Both statements correctly output U.
Example 2:
Printf ("% d \ n", string [6]);
Printf ("% d \ n", P [6]);
Both statements correctly output the U address.
Example 3:
Printf ("% C \ n", * (p + 1 ));
Printf ("% C \ n", P [1]);
The two statements have the same effect.
Note: Both P and string point to the first address of the string.