C++ Return Array from Functions1 min read

C++ allows us to return the arrays from a function. However the actual array values cannot be returned, so we return the array from the function with the help of pointers.

Pointers are the variables that hold an address. With the help of pointers, the address of the first element is returned from a function. The name of the array is itself points to the first element.

In order to return the array from the function, we need to declare a function returning a pointer in a one-dimensional array. Example: syntax of returning function

Also, C++ does not allow to return the address of the local variable from the function, so we need to declare the local variable as static in a function.


Example of C++ Return Array from Functions

Output:


MORE

Keith Number Program in C

In this tutorial, we will write a Keith number in C. It is one of the most asked questions in an interview. Before that, you …
Read More

Keith Number Program in C++

In this tutorial, we will write a Keith number in C++. It is one of the most asked questions in an interview. Before that, you …
Read More

Singly linked list Program C++

In this tutorial, we will write a C++ program to implement singly linked list. In this program, we will create a separate function for each …
Read More

Fascinating Number Program in C

In this tutorial, we will write a C program to check whether the given number is a Fascinating number or not. You may go through …
Read More

Peterson Number in C

In this tutorial, we will learn about the Peterson number and check if the number is Peterson or not in C. What is Peterson Number? …
Read More

Peterson Number in C++

In this tutorial, we will learn about the Peterson number and write a C++ program to check if the given number is a Peterson number …
Read More