About 446,000 results
Open links in new tab
  1. c++ - Return array in a function - Stack Overflow

    Aug 13, 2010 · C++ does not allow to return an entire array as an argument to a function. However, you can return a pointer to an array by specifying the array's name without an index. If you want to return a single-dimension array from a function, you would have to declare a function returning a pointer as in the following example:

  2. How to Return a Local Array From a C++ Function?

    Dec 14, 2022 · Here, we will build a C++ program to return a local array from a function. And will come across the right way of returning an array from a function using 3 approaches i.e. Using Dynamically Allocated Array; Using Static Array ; Using Struct

  3. How to Return an Array in a C++ Function - DigitalOcean

    Aug 3, 2022 · In this tutorial, we are going to understand how we can return an array from a function in C++. Methods to Return an Array in a C++ Function. Typically, returning a whole array to a function call is not possible. We could only do it using pointers.

  4. How to Return an Array from a Function in C++ - Tutorial Kart

    In C++, you can write functions that return arrays. Since arrays are not directly returnable by value, alternative methods like pointers, std::array , or std::vector are often used. In this tutorial, we will cover different approaches to return arrays from functions.

  5. How to Return an Array From a Function in C++ | Delft Stack

    Mar 12, 2025 · This article explains how to return an array from a function in C++. Learn various methods including returning a pointer to a dynamically allocated array, using std::array, and utilizing std::vector.

  6. Return an Array in C - GeeksforGeeks

    Jun 28, 2024 · One of the most common ways to return an array from a function in C is by using pointers. This involves allocating memory for the array within the function and then returning a pointer to this memory.

  7. c++ - How to return an array from a function? - Stack Overflow

    Nov 24, 2010 · It is not possible to return an array from a C++ function. 8.3.5[dcl.fct]/6: Functions shall not have a return type of type array or function[...] Most commonly chosen alternatives are to return a value of class type where that class contains an array, e.g.

  8. C++ function to return array - Stack Overflow

    May 30, 2012 · You can't return an built-in array or a function from a function. In other words, the return type of a function can't be a built-in array or a function type. But you can return a pointer to either of those. Other option is to use std::array or std::vector as the return type. One example using std::array is shown below:

  9. Return Array from Functions in C++ - Online Tutorials Library

    Learn how to return arrays from functions in C++ with this comprehensive guide. Explore examples and best practices for effective array management.

  10. How do I correctly return an array from a function?

    In C a function can only return one element, so to return an array you must return a pointer which can contain the address of the first element of that array. And that's what you're doing in your code. You can access both values by correctly indexing the …

  11. Some results have been removed