I have a question when I see 's answer that I don't know how to behave when I refer to charstr[] with a pointer.
Why shouldn't I write printf("str:%s\n",p);
?
Why shouldn't I write printf("str:%s\n",p);
What made you think so?I think there is no problem with the code.
printf("*p:%s\n", &(*p))
is good and printf("str:%s\n",p);
is not bad.
If anything, printf("*p:%s\n", &(*p))
is more problematic.
&(*p))
may be intended to indicate that it is an address, but it is not usually written in this way.
In char*p;
, &(*p)
and p
are the same.By the way, &(*(&(*p)))
is the same as p
.
&Area means the address of the area, and *Address is the content of the area that the address points to.
If p contains a char-type area address, contains zero or more character codes in that area, and is zero-terminated, printf("str:%s\n", &(*p))
works fine as well as printf("str:%s\n",p);
.
I don't remember saying no, but if you want to take it and solve it yourself, check it out yourself until you realize there's no problem.
Is there an environment where I can check it?
The printf is also detailed in Wikipedia.
If you feel like it, you can check the definition files of various operating systems.
I think you can check the definition of the header.
© 2025 OneMinuteCode. All rights reserved.