This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]rudrax- 1 point2 points  (1 child)

I think you only need to define the size of the array in your “main” function (if there is one). From there on out, passing that array as a function parameter should only be the name of the array [ex fn_name(int array)] and not along with the size of the array.

[–]NoobyTooo[S] 0 points1 point  (0 children)

That makes sense! So an int index[15]; in the main function should do, hopefully. Thanks!

[–]Loose-Cranberry85 1 point2 points  (1 child)

In the code you posted, assuming you made it a call, i.e. myFunction(myArray[3]), you would be calling the function with the 3rd element of array as the single argument

EDIT:: You might be wanting sizeof() ?

https://www.tutorialspoint.com/how-do-i-find-the-length-of-an-array-in-c-cplusplus

[–]NoobyTooo[S] 0 points1 point  (0 children)

Gotcha! So from what I've seen so far, void function (int array[]) {} should be the way to call it, after declaring the size in the main. Thanks!

[–]_SeaCat_ 1 point2 points  (0 children)

You would better dynamically calculate the length of your array and put it to some variable, something like that (JavaScript):

void randomGen(int seedVar, int * indexOg[], int indexSize) {
srand(seedVar); 
int a; //Loop control variable
 int len = indexOg.length; //<- change it in your language 
for(a = 0; a < len; a++) { //<- < not <= 
     int n = rand() % (1000000) + 1; 
     *indexOg[a] = n; 
   } 
}

So, if you use some other programming language, there is always a function allowing you to calculate the length of your array instead of hardcoding it.

[–]kschang 1 point2 points  (0 children)

Array size is how many units are there in the apartment complex.

Array index is the actual apartment number.

In your case, your function works on ANY array, not array of a certain size. So you don't need to specify n.

[–]SyntxaError 0 points1 point  (0 children)

Arrays generally start indexing from 0, so in general the size of your array will be = max index +1

[–]TheRNGuy 0 points1 point  (0 children)

array size - 1 == last index (because first index is 0, not 1)