Consider an example:
void main()
{
int *arr;
arr=new int[10];
}
How can I know the size of arr?
You have to keep track of it yourself. I'd recommend making life easier on yourself by using a vector or deque instead.
Two ways (please note that in the first arr is a ptr not an int):
int main()
{
const int SIZE = 10;
int* arr;
arr = new int[SIZE];
delete[] arr;
}
or better yet:
int main()
{
std::vector<int> arr( 10 );
std::size_t size = arr.size();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With