No, C does not have such functionality built in. Moreover, there is no functionality to get the upper boundary of an array once you pass it to a function (so called "decaying to pointers").

There are two standard solutions to this problem:

  • Pass a pointer to the first array element and the count of elements, or
  • Pass a pointer to the whole array, an index to the initial element, and an index to the last element

The first approach would look like this:

int sum_array(int* array, size_t len) {
    int res = 0;
    for (size_t i = 0 ; i != len ; i++) {
        res += array[i];
    }
    return res;
}
...
int ProfitA = sum_array(array, A);
int ProfitB = sum_array(array+A, B);
int ProfitC = sum_array(array+A+B, N-A-B);

the second approach would look like this:

int sum_array(int* array, int first, int last) {
    int res = 0;
    for (int i = first ; i <= last ; i++) {
        res += array[i];
    }
    return res;
}
...
int ProfitA = sum_array(array, 0, A-1);
int ProfitB = sum_array(array, A, A+B-1);
int ProfitC = sum_array(array, A+B, N-1);
Answer from Sergey Kalinichenko on Stack Overflow
๐ŸŒ
NIST
math.nist.gov โ€บ javanumerics โ€บ array โ€บ doc โ€บ array.Range.html
Class array.Range
Create a range with a specified stride. ... Return the number of elements in a range.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ range-and-coefficient-of-range-of-array
Range and Coefficient of range of Array - GeeksforGeeks
September 9, 2022 - // C implementation to find // Range and coefficient of range #include <stdio.h> int min(int a,int b) { int min = a; if(min > b) min = b; return min; } int max(int a,int b) { int max = a; if(max < b) max = b; return max; } // Function to return ...
Discussions

java - Fill arrays with ranges of numbers - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Is there any syntax/package allowing quick filling of java arrays with ranges ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to create an array and fill it with a specific range of numbers?
Hi, hope everyone is well. We were assigned homework and this was one of the problems. I know how to declare an array and to use it in various contexts, but I cannot figure out how to fill an int array with a specific set of numbers (i.e. More on reddit.com
๐ŸŒ r/learnjava
23
28
December 7, 2020
arrays - Range values in C - Stack Overflow
So I want to solve a problem in C We have 10 numbers {1,1,8,1,1,3,4,9,5,2} in an array. We break the array into 3 pecies A, B, C. And wemake the bellow procedure (I prefered to create a small diag... More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - Pulling a range from an array - Stack Overflow
So I donโ€™t want anyone to solve it but just help me out in terms of working a certain part. So out of the array I have to print a certain numbers that fit within the range given(0 & 50). Besides manually putting array[i]>= 0 && array[i] <=50 ยท How can I make it so it test over multiple values and draws the numbers from there. I seem to be stuck on that part. ... See similar question at C#. you can apply the solutions to JS too. ... Are you asking about JavaScript ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Reddit
reddit.com โ€บ r โ€บ learnjava โ€บ comments โ€บ k890sd โ€บ how_to_create_an_array_and_fill_it_with_a
How to create an array and fill it with a specific range of ...
December 7, 2020 - Hi, hope everyone is well. We were assigned homework and this was one of the problems. I know how to declare an array and to use it in various contexts, but I cannot figure out how to fill an int array with a specific set of numbers (i.e.
Top answer
1 of 3
1

This is my take. It is a greedy algorithm that starts with a maximal B range and then starts chopping off values one after another until the result cannot be improved. It hast complexity O(n).

#include <iostream>
#include <utility>
#include <array>
#include <algorithm>
#include <cassert>

// Splits an array `arr` into three sections A,B,C.
// Returns the indices to the first element of B and C.
//    (the first element of A obviously has index 0)
template <typename T, ::std::size_t len>
::std::pair<::std::size_t,::std::size_t> split(T const (& arr)[len]) {
  assert(len > 2);
  // initialise the starting indices of section A, B, and C
  //   such that A: {0}, B: {1,...,len-2}, C: {len-1}
  ::std::array<::std::size_t,3> idx = {0,1,len-1};
  // initialise the preliminary sum of all sections
  ::std::array<T,3> sum = {arr[0],arr[1],arr[len-1]};
  for (::std::size_t i = 2; i < len-1; ++i)
    sum[1] += arr[i];
  // the preliminary maximum
  T max = ::std::max({ sum[0], sum[1], sum[2] });
  // now we iterate until section B is not empty
  while ((idx[1]+1) < idx[2]) {
    // in our effort to shrink B, we must decide whether to cut of the
    //   left-most element to A or the right-most element to C.
    //   So we figure out what the new sum of A and C would be if we
    //   did so.
    T const left = (sum[0] + arr[idx[1]]);
    T const right = (sum[2] + arr[idx[2]-1]);
    // We always fill the smaller section first, so if A would be
    //    smaller than C, we slice an element off to A.
    if (left <= right && left <= max) {
      // We only have to update the sums to the newly computed value.
      // Also we have to move the starting index of B one
      //    element to the right
      sum[0] = left;
      sum[1] -= arr[idx[1]++];
      // update the maximum section sum
      max = ::std::max(sum[1],sum[2]); // left cannot be greater
    } else if (right < left && right <= max) {
      // Similar to the other case, but here we move the starting
      //    index of C one to the left, effectively shrinking B.
      sum[2] = right;
      sum[1] -= arr[--idx[2]];
      // update the maximum section sum
      max = ::std::max(sum[1],sum[0]); // right cannot be greater
    } else break;
  }
  // Finally, once we're done, we return the first index to
  //    B and to C, so the caller knows how our partitioning looks like.
  return ::std::make_pair(idx[1],idx[2]);
}

It returns the index to the start of the B range and the index to the start of the C range.

2 of 3
0

This is your pseudocode in C (just for reference because you tagged your problem with C++ yet want a C only solution). Still, the greedy solution that bitmask provided above is a better O(N) solution; you should try to implement that algorithm instead.

#include <stdio.h>
#include <stdint.h>
#include <limits.h>

#define N 10

int sum_array(int* array, int cnt)
{
    int res = 0;
    int i;
    for ( i = 0; i < cnt ; ++i)
        res += array[i];
    return res;
}

int main()
{
    int array[N] = {1,1,8,1,1,3,4,9,5,2};
    int Min = 0;
    int bestA = 0, bestB = 0, bestMin = INT_MAX;
    int A, B;
    int i;
    for ( A = 0; A < N - 2; ++A)
    {
        for ( B = A + 1; B < N - 1; ++B)
        {
            int ProfitA = sum_array(array, A + 1);
            int ProfitB = sum_array(array + A + 1, B - A );
            int ProfitC = sum_array(array + B + 1, N - 1 - B );

            //here the values are "current" - valid
            Min = (ProfitA > ProfitB) ? ProfitA : ProfitB;
            Min = (ProfitC > Min) ? ProfitC : Min;

            if( Min < bestMin )
                bestA = A, bestB = B, bestMin = Min;
#if 0           
           printf( "%2d,%2d or (%3d,%3d,%3d) ", A, B, ProfitA, ProfitB, ProfitC );
           for( i = 0; i < N; ++i )
               printf( "%d%c", array[i], ( ( i == A ) || ( i == B ) ) ? '|' : ' ' );
           printf( " ==> %d\n", Min);
#endif           
        }
    }
    printf("%d @ %d, %d\n", bestMin, bestA, bestB);
    return 0;
}
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 658900 โ€บ java โ€บ Array-range-numbers
Array range of numbers (Beginning Java forum at Coderanch)
December 10, 2015 - It take the numbers given as arguments and produces a Stream containing the appropriate range of numbers in order. Then you can simply use the toArray method method to get an array.
Find elsewhere
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 55194467 โ€บ pulling-a-range-from-an-array
java - Pulling a range from an array - Stack Overflow
The clean solution in java would be using streams. You can do much more than just filter, but this would solve your question. Copyint[] filterByRange(int[] array, int min, int max) { return Arrays.stream(array) .filter(i -> min <= i && i<= max) .toArray(int[]::new); }
๐ŸŒ
Blogger
elab-c.blogspot.com โ€บ 2017 โ€บ 03 โ€บ array-range.html
eLAB for Programming: Array Range
March 27, 2017 - Range of an array is the difference between the maximum and minimum element in an array, Input and Output Format: Input consists of n+1 integers where n corresponds to the number of elements in the array.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ find-the-range-of-numbers-in-an-array-in-c
How to Find the Range of Numbers in an Array in C? - GeeksforGeeks
July 23, 2025 - Find the range of the array by subtracting the value of min from the max. Return the value of range as a result. The following program illustrates how we can find the range of numbers in an array in C.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ java โ€บ array range in java
Array Range in Java | Delft Stack
October 12, 2023 - This method is defined in java.util.Arrays Class. This method copies the specific range of elements from the given original array to a new array and then returns this array.
๐ŸŒ
Medium
medium.com โ€บ javarevisited โ€บ understanding-java-arrays-from-basics-to-length-and-limits-9c30f749f2fd
Understanding Java Arrays: From Basics to Length and Limits | by sajith dilshan | Javarevisited | Medium
August 25, 2025 - This creates an array with 4 slots, all starting at 0.0. ... Here the array automatically has 3 elements since you listed 3 items. Arrays in Java use an int to store how many elements they can hold.
๐ŸŒ
How to do in Java
howtodoinjava.com โ€บ home โ€บ java array โ€บ create a subarray in java: copyofrange(), arraycopy, streams
Create a Subarray in Java: copyOfRange(), arraycopy, Streams
July 19, 2018 - The length of the result is to โ€“ from, and a range with from == to is a valid empty subarray. The to index is exclusive, so the subarray length is to minus from ยท When our own code works with an inclusive end, such as โ€œsteps 2 to 4โ€ typed by a user, we pass end + 1 as to. Mixing the two conventions is the most common cause of a subarray that is one element short. int start = 1; int endInclusive = 3; String[] picked = Arrays.copyOfRange(new String[]{"a", "b", "c", "d", "e"}, start, endInclusive + 1); // [b, c, d] int size = picked.length; // 3
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 705410 โ€บ java โ€บ Arrays-range
Arrays in range (Java in General forum at Coderanch)
You'll have to delete the matching closing braces as well. Thank you so much! I do have one last question though. I am trying to Nest my for loops First for loop goes through array Second for loop inside of the first loop adds a * as long as the int is less than the number at the index defined in your first for loop.
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ how to return the values from an array within a certain range.
r/javahelp on Reddit: How to return the values from an array within a certain range.
January 28, 2016 -

I have a method that is asking me to return all the values within a range and put them into a new array. So...{4, 5, 6, 7, 8} with a range of 5 to 7 would become a new array of {5, 6, 7}. Hopefully that makes sense. I looked into the copyOfRange method but that uses the indexes and I need to use the given numbers from the range. I don't have the actual range numbers so I have to write a method that can account for any given range. Thanks in advance.

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-util-arrays-copyofrange-java
Arrays.copyOfRange() in Java with Examples - GeeksforGeeks
November 11, 2024 - Below is a simple example that uses Arrays.copyOfRange() method to copy a specified range of elements from an existing array. ... import java.util.Arrays; public class Main { public static void main(String[] args) { // Original array int[] arr1 ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ java โ€บ util โ€บ arrays_copyofrange_short.htm
Java Arrays copyOfRange() Method
The Java Arrays copyOfRange(short[] original, int from, int to) method copies the specified range of the specified array into a new array.The final index of the range (to), which must be greater than or equal to from, may be greater than ...