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
constint 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