About 24,800,000 results
Open links in new tab
  1. 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. To return an array using pointer follow the below syntax: Here, arr is the name of the pointer pointing to the array. n is the size of the array.

  2. Returning an array using C - Stack Overflow

    To return an array, create one outside the function, pass it by address into the function, then modify it, or create an array on the heap and return that variable. Both will work, but the first doesn't require any dynamic memory allocation to get it working correctly.

  3. How to return an array in c - Stack Overflow

    Dec 26, 2013 · The proper C solution is to use malloc to allocate an amount of space that you can use as an array, and return the pointer to that array. double * myFunc(){ double * v = malloc(10*size of(double)); return v; }

  4. c - How do I correctly return an array from a function ... - Stack Overflow

    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 …

  5. C Return Arrays from Function - Online Tutorials Library

    In C, a function can be made to return an array by one of following methods −. Passing the array as argument and returning the pointer; Declaring a static array in a function and returning its pointer; Using malloc() function; Embedding the array inside a struct variable and passing it …

  6. How to Return an Array in C - HatchJS.com

    To return an array from a function, you can use the following steps: 1. Declare the array in the function’s parameter list. 2. Allocate memory for the array. 3. Initialize the elements of the array. 4. Return the array from the function. For example, the following function returns an array of integers: c int* getArray()

  7. C Program: Read and Print elements of an array - w3resource

    Mar 18, 2025 · printf("\nElements in array are: "); . for(i=0; i<10; i++) . printf("%d ", arr[i]); // Print each element in the array. printf("\n"); return 0; . Explanation: printf("Input 10 elements in the array :\n"); . for(i=0; i<10; i++) . printf("element - %d : ",i); scanf("%d", &arr[i]); . printf("\nElements in array are: "); . for(i=0; i<10; i++)

  8. Return an Array in C Language - PiEmbSysTech

    Sep 14, 2023 · To work with arrays in C, including returning arrays from functions, you typically employ one of the following strategies: Returning a Pointer: Instead of returning the entire array, you can return a pointer to the array. This pointer points to the memory location of the first element of the array.

  9. Return an Array in C - Tpoint Tech - Java

    Mar 17, 2025 · Returning array by passing an array which is to be returned as a parameter to the function. Returning array using malloc () function. In the above code, we have created the variable arr [] as static in getarray () function, which is available throughout the program.

  10. Returning an Array in C - Tutoline

    This article will guide you on how to return an array in C. To return a single-dimensional array from a function in C, you can use a pointer as the return type. Here’s an example: int* arr = malloc(size * sizeof(int)); // Populate the array with values. for (int i = 0; i < size; i++) { arr[i] = i + 1; return arr; int size = 5;

  11. Some results have been removed
Refresh