Practice with Functions
References and Reference Parameters
- call-by-value : a copy of the argument's value is made and passed
to the called function. Changes to the copy inside of called function do not
affect the original variable's value in the caller.
- call-by-reference : The caller gives the called function the ability
to directly access the caller's data, and to modify that data if the called
function so chooses.
See Fig. 3.20 from the textbook "C++ How to
Debugging using cout to display information in a program.
- Read two natural numbers x and y, and add the multiplications of the values
(i*j), where 1 <= i <= y, 1 <= j <= x.
- Read a number i from a terminal, and draw the following
figure having i rows. For example, when i = 5, the program
displays as follows:
+ + +
+ + + +
+ + + + +
- Generate a random number. If the value of the random number is multiple of 3,
then display the
old random number that is already displayed and display the current random number
in one line. Define a function check_random() which evaluate the random
number being the multiple of 3. If it is multiple of 3, display the old and
new numbers, then return the old value substituted with current number.
(Hint: You may need to include the header file and
to use time(0), srand() and rand() functions to generate a random number.)
BU CAS CS - Practice with Functions
Last Updated on: Jan 23, 2000
This page created by Jaehee Yoon <firstname.lastname@example.org>.
Some code examples taken from the textbook "C++ How to Program", by
Deitel and Deitel.