KRHS Internet Lesson

Teacher Name:Mr. Rung                          Date of Lesson: January

Course Name: C++                    Lesson Name: Chap 9.1c

Student Name

Password


Objective
To complete the workbook questions.


Primary Focus

Using the following program, answer the questions below.
 

 #include  
 
 //FUNCTION PROTOTYPES 
 void the-function(int g, int & p); //one integer is passed by value 
 //the other by reference 
 
 int main() 
 {
 int k = 8, m = 8; 
 cout « "The value of k is "« k « endl; //initial value of k cout « "The value of m is "« m « endl; / /initial value of m 
 
 the-function(k, m); 
 cout « "After the function call \n" ;
 cout « "k = " « k «endl; 
 cout « "m = " « m « endl; 
 
 return 0; 
 } //MAIN 
 
 void the-function (int g, int & p) 
 { 
 
 g = g + 2; 
 p = p + 5; 
 
 cout « "While in the function \n"; 
 cout « "g = " « g «endl; 
 cout « "p = " « p «endl; 
 
 }//THE-FUNCTION 
 
 

Site Links
Course Home Page

Additional Resources

Site Links


Question #1

Are the values of k and m in the main function the same after the function call?


Question #2

What does the symbol & mean in the function prototype and in the function definition?


Question #3

What will the output to the screen look like after the program is executed?


Question #4

Why should you pass parameters by value when possible instead of by reference?


Question #5

What value is passed to the variable g?