Ask coding questions

← Back to all posts
How can I print the object values instead of their addresses?
DarkHollow (0)

Also, how can I make a ptr pointer to an array of vehicles (dynamically) and then print them? Let's I want to use ptr as an array.
If ptr is an array pointer, how can I get its size?

Thank you!

xxpertHacker (860)

I'm surprised that no one has answered this yet...

Pointers are just addresses, they don't necessarily even have a length, therefore you have to associate the length with it and carry it around.

To get the value that a pointer points to, you'd have dereference it, *ptr, as for printing the value, that's a custom thing that you'd have to do on your own.

Maybe you shouldn't be using something like T*, but std::span<T>, std::vector<T>, or a custom array class?