Start here · Essential guide
How to Return an Array in C++
Learn how to return an array from a C++ function. Compare std::vector, std::array, unique_ptr, and struct wrappers, and avoid returning a dangling pointer.
Strings, Containers and Memory
Ways to return an array from a C++ function and how char arrays and pointers differ.
Start here · Essential guide
Learn how to return an array from a C++ function. Compare std::vector, std::array, unique_ptr, and struct wrappers, and avoid returning a dangling pointer.
No, char[] and char * are different types in C. An array holds its own elements, while a pointer only stores an address. Here's what changes in practice.
Yes. In C, an array is passed as a pointer to its first element, so you must pass its length too. This guide shows a working example and the common mistakes.
return {} sends back a value-initialized object of the return type: 0 for int, an empty vector or string, nullptr for pointers, and zeros for std::array.
Related topics