Question about memory address
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.
Code:
// Ex3_10.cpp
// Counting string characters using a pointer
#include <iostream>
using namespace std;
int main()
{
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:"
<< endl;
cin.getline(buffer, MAX, '\n'); // Read a string until \n
while(*pbuffer) // Continue until \0
pbuffer++;
cout << endl
<< "The string \"" << buffer
<< "\" has " << pbuffer-buffer << " characters.";
cout << endl;
return 0;
}
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?
Thanks in advance for whoever answers this.