A C++ program may return a pointer, just is may have them passed to the function.
To specify a pointer, you define that data type in the return type. For example:
int* genericFunction()
{
int* list;
// do things
return list;
}
The book gives an example on how to return an array this way, however, as it uses an existing array, the array is already passed to it by reference, so you don’t need to return the array.
So while there are times when you need to return a pointer, it isn’t needed very often. especially with primitive data, or the types we’ve seen so far.
Returning Pointers from a Function in C++ was originally found on Access 2 Learn
One Comment
Comments are closed.