I am new to c++ and I am trying to create a function to return a value from an array. Here are the instructions for the assignment:
In this exercise, you will create a function to return a value from an array. If the index is out of range, return 0.
Function Name: read01
Parameters: (data,size,index)
1) data: An array of constant int's
2) size: An int, the number of slots in data
3) index: An int, the desired position in data
Return Value: An int, the value of position index in data, or 0.
Here is what I tried so far:
int read01(int data[], int size, int index){
return data[index];
}
I know how to do the "if" statement so that's not an issue, but where I am confused is how to define the size parameter as the size of data[]. I know you cannot put "int size" into the data parameter like so, "int data[int size]", but I cannot figure out another way to do it. Any help would be appreciated!
int data[],is correct alreadysizeparameter. Your function does not create or resize any arrays, it reads a value out of an array that already exists