I had read few time about the function but i seem like don't get what is pass by value and pass reference,also how i use return value in the function. Please help me understand clearly.
this code below i don't know is correct or not
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//3.A void function to calculate total points and GPA for one student
void Calculate_GP(float count, int Units,float &Average)
{
float Total_Point;
int Sum = 0;
Sum += Units;
Total_Point += count;
if(Counter > 0)
Average = Total_Point/Sum;
else
Average = 0;
return;
}
count and Units are passed by value. That means that count and Units is just copies of the arguments you pass to the function.
Average is passed by reference. You can see that Average is a reference because it has & before it's name on line 2. Changes to Average will also affect the third argument passed to the function.