Is there a way to determine the size of a char[]
buffer via a char*
pointer in C++? I'm using C++98.
The following lines of code all print out '8' (essentially sizeof(char*)
). However I'm looking for the actual size of the buffer.
int maxBufferLen = 24;
char* buffer = new char[maxBufferLen];
std::cout << sizeof(buffer) << std::endl; // prints '8'
std::cout << ( sizeof(buffer) / sizeof(buffer[0]) ) << std::endl; // prints '8'
In practice, I am passing that char*
buffer in between functions and I will not have access to the maxBufferLen
variable that I am using to initialize it. As such, I'll need to determine the length using another way.