Hi I have another question. I was reading my tutorial and there's a sample program to count the number of characters an user entered with a pointer array.
What I don't get is the bolded part, pbuffer-buffer. How does that output the number of characters? Wouldn't that show the bytes of memory the string takes up since they point to memory address?
// Counting string characters using a pointer
using namespace std;
const int MAX = 80; // Maximum array dimension
char buffer[MAX]; // Input buffer
char* pbuffer=buffer; // Pointer to array buffer
cout << endl // Prompt for input
<< "Enter a string of less than "
<< MAX << " characters:"
cin.getline(buffer, MAX, '\n'); // Read a string until \n
while(*pbuffer) // Continue until \0
cout << endl
<< "The string \"" << buffer
<< "\" has " << pbuffer-buffer << " characters.";
cout << endl;
Thanks in advance for whoever answers this.