help with understanding pointers

Iam trying to understand pointer in c++.
I understand that a pointer points to a memory address.
Why does this code use *pbuffer only some of the time?
Thanks for the help.

1
2
3
4
5
6
7
8
9
10
11
12
       const int max{ 80 };
	char buffer [max];
	char* pbuffer{ buffer };

	cout << "get line" << max << "chars" << endl;
	cin.getline(pbuffer, max, '\n');
	while (*pbuffer)
		pbuffer++;

	cout << endl << "the string\"" << buffer << "buffer has" << pbuffer - buffer << "char";
	cout << endl;
  Put the code you need help with here.
while(*pbuffer) will execute as long as the character at pbuffer is not null;
pbuffer++ will increment the pbuffer pointer by 1 character
pbuffer - buffer will tell you how many characters are in buffer
Thanks for the reply. I was wondering why u need to while(*pbuffer) instead of while(pbuffer)
The character string will usually be ended by a null char, which would stop the while loop and accurately get the character count.
Topic archived. No new replies allowed.