First of all, I suggest you use an editor to debug, put a breakpoint on the printf line, and then look in the monitor to see what p and *p point to respectively. Then, p is a character pointer type, pointing to the address of the first element of a character array, *p takes the value pointed to by p, which is the first element. If you understand, you can think about the results of p++,*p++, and what is the value of p after the operation
First of all, there is no such type of string in C. Strings in C are character arrays terminated by null characters. Then, the p pointer saves not the string, but the head of the character array. The address of the element. So you can use the indirect operator * to read the value in this address, which is the first element of this character array.
Because the type of p here is a pointer, the string xxx is stored in the memory address it points to. If you use p directly, the output is the memory address pointed to by p. Add an * in front of it to output The content pointed to by this pointer.
First of all, p is a pointer type, which stores an address, and this address is index, which can be understood as the address of the first character of the entire string (actually not a string) , similar to the first element in an array. *This symbol refers to defining a pointer variable when it is defined, and when it is called, it takes the value in the address. printf("%c",*p);, if you don’t add * to your statement, it means that what you output is the value of p, but the value of p is an address, so you will naturally not get the p address. The value that actually exists. By adding *, you can get the value stored at this address.
p is a pointer type. It stores the address pointing to the element. If is not added, the specific address is printed. After adding the sign, it is the element pointed to
First of all, I suggest you use an editor to debug, put a breakpoint on the printf line, and then look in the monitor to see what p and *p point to respectively.
Then, p is a character pointer type, pointing to the address of the first element of a character array, *p takes the value pointed to by p, which is the first element.
If you understand, you can think about the results of p++,*p++, and what is the value of p after the operation
First of all, there is no such type of string in C. Strings in C are character arrays terminated by null characters.
Then, the p pointer saves not the string, but the head of the character array. The address of the element.
So you can use the indirect operator * to read the value in this address, which is the first element of this character array.
Because the type of
p
here is a pointer, the string xxx is stored in the memory address it points to. If you usep
directly, the output is the memory address pointed to byp
. Add an * in front of it to output The content pointed to by this pointer.First of all,
p
is a pointer type, which stores an address, and this address isindex
, which can be understood as the address of the first character of the entire string (actually not a string) , similar to the first element in an array.*
This symbol refers to defining a pointer variable when it is defined, and when it is called, it takes the value in the address.printf("%c",*p);
, if you don’t add*
to your statement, it means that what you output is the value ofp
, but the value ofp
is an address, so you will naturally not get thep
address. The value that actually exists. By adding*
, you can get the value stored at this address.You can also add "*" without adding it. You can also use array subscript to output the first character
p is a pointer type. It stores the address pointing to the element. If is not added, the specific address is printed. After adding the sign, it is the element pointed to