0

Why passing an array of two elements to function execution takes the same time as passing an array of 2 million elements?

int execution (int arr_data[],int size);

This is a sample function prototype in C.

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Faseeh
  • 23
  • 4
  • 2
    See https://stackoverflow.com/a/6567846/9347959 – M. Zhang Jul 05 '21 at 06:28
  • Can you give the full code? Ideally it shouldn't take same amount time, but if the time complexity is O(1), i.e. the function isn't dependent on array size, then it explains same execution time. But it is difficult to confirm without full code – Ankush Pandit Jul 05 '21 at 06:29
  • 1
    All that's being passed is a pointer to an array. The size of the data pointed to is irrelevant, there's no copy happening other than the integer pointer. – ggorlen Jul 05 '21 at 06:31
  • @AnkushPandit we are not given full code only they asked if they are getting same execution time and independent of the number of elements passed to the array. My Best guess is that because they are sending pointers rather than values? What do u say ? – Faseeh Jul 05 '21 at 06:32
  • @ggorlen Yeah I have been thinking the same pointer approach. – Faseeh Jul 05 '21 at 06:33

0 Answers0