I'm a beginner in C++ and my teacher is not explaining the material correctly. I was wondering if I could get help
can someone explain this to me?
Collapse
X
-
Tags: None
-
i'm in deltamami's class and this is what the teacher told us about those problems: well, about number one
first of all... this should not be a main( ) function...
second... the function should have an array passed to it (by passing a pointer to the first element), and an integer value that you will search for in the array, and one other variable that you will need for the loop control
third... the function should return a pointer to the value in the array
How will you find the value in the array? Loop through the array and compare each value to the value you are looking for. When you find the value, return the address of the value in the array (the location of the first element of the array plus the number of ints from the beginning of the array).
I dont understand what this means
Originally posted by LaharlWhat problem are you having? What material is he not explaining well? We're gonna need more information than that to help you...Comment
-
is this right?
[CODE=cpp]void loadArray(const int*, const int);
int main()
{
//Declare variables
int myArray[5]; //IN: holds the array of integers
loadArray(myArr ay, 5); //IN: invokes loadArray
system("pause") ;
return 0;
}
void loadArray(const int *myArray, const int size)
{
//Increments the address
for(int i = 0; i< size; i++)
cout<<(myArray+ i)<<endl; //My array is incremented and therefore prints out
//the information in the array
}[/CODE]
Originally posted by kandigirl2009i'm in deltamami's class and this is what the teacher told us about those problems: well, about number one
first of all... this should not be a main( ) function...
second... the function should have an array passed to it (by passing a pointer to the first element), and an integer value that you will search for in the array, and one other variable that you will need for the loop control
third... the function should return a pointer to the value in the array
How will you find the value in the array? Loop through the array and compare each value to the value you are looking for. When you find the value, return the address of the value in the array (the location of the first element of the array plus the number of ints from the beginning of the array).
I dont understand what this meansComment
Comment