Code:
int calcaverage(int *, int *); //declaration
int calcaverage(int HowMany, int *Scores) //definition
{
...
...
}
Do the types in red match? Look at the types in blue--they do match. I suggest you do this:
1) Do not declare your functions
2) Write your functions
3) After you write your functions, copy the function header and paste it where you would place the function declaration.
4) Type a semi colon after the function header you pasted.
Here is an example:
Step 1) and 2):
Code:
#include <iostream>
using namespace std;
int main()
{
int result = someFunc(1, 2);
cout<<result<<endl;
return 0;
}
int someFunc(int a, int b)
{
return a+b;
}
Steps 3) and 4):
Code:
#include <iostream>
using namespace std;
int someFunc(int a, int b);
int main()
{
int result = someFunc(1, 2);
cout<<result<<endl;
return 0;
}
int someFunc(int a, int b)
{
return a+b;
}
Here is some basic information on pointers:
All variable names and their corresponding values are stored in memory somewhere. The location in memory where they each reside is denoted with an address. An address is somewhat scary looking:
006BFDF4
but you can just think of it as a mailbox number. If you look inside the mailbox with that address, you'll find the variable and its value. A pointer is a variable that stores the address of another variable.
If you declare an int like so:
int num = 10;
that line stores the variable num with a value of 10 somewhere in memory. We don't know where it is in memory yet. However, there is an "address of" operator which will get the address of num, e.g.
cout<<&num<<endl;
You can store that address in a special variable called a pointer:
int* p;
That declares a variable named p, and p is a variable of type "pointer to int". Essentially, you read the line in reverse. I suggest you adopt the notation where the * is adjacent to int--not adjacent to p:
int *p;
The first notation will make it clear to you that the type is int*, which is "pointer to int", and p is the variable name.
Now, you can assign the address of any int to p:
p = #
which reads: "p equals the address of num".
Finally, you can also use a pointer to get the value stored at that address by putting a little star in front of the pointer name:
cout<<*p<<endl;