C++ Direct Court Pointer Name Meaning?


First, look at the following code example:

#include <iostream>
using namespace std;
int main()
 char *str = "this is a test";
 cout << "str=" << str << endl;
 cout << "*str=" << *str << endl;
 cout << "&str" << &str << endl;
 return 1;

The output results are as follows:

See some examples of direct useCout * pointer nameAt first, I felt very confused. I thought I would output the pointer directly. The output was the content stored in the memory pointed by the pointer until the end of reading the “/0” sign. Later, it was found that this was a pre-set rule of the compiler, and that was the output of the compiler. In addition, if * STR is used directly, where the str pointer variable stores the first address of the variable it points to, then the content of * STR output is naturally easy to understand the first character of the pointer pointing to the content.


Above is the whole content of this article. I hope the content of this article has some reference value for your study or work. Thank you for your support to developpaer. If you want to know more about it, please check the links below.