Problem Solving with C++, Student Value Edition
Problem Solving with C++, Student Value Edition
10th Edition
ISBN: 9780134543680
Author: Walter Savitch
Publisher: PEARSON
Question
Book Icon
Chapter 5.2, Problem 12STE
Program Plan Intro

void Functions:

  • A function must either return a single or no value.
  • A function where no value is returned is termed as “void” function.
  • The “void” function is been defined in same way as function that would return a value.
  • It implements only subtask for complete problem.
  • If a “void” function is called, formal parameters are substituted with arguments.
  • The statements in function body are executed.
  • The “return” statement specifies value that is been returned.

Call-by-Reference:

  • It is a method for substituting arguments.
  • The argument is substituted for formal parameter.
  • The function call arguments may be a variable.
  • This argument variable is substituted for formal parameter.
  • It is similar to copying of argument variables into function definition body in place of formal parameter.
  • The function body code is been executed once argument is substituted.
  • This code can change argument variable value.
  • The ampersand sign (&) is attached to end of type name in formal parameter list in both function declaration as well as function header definition.

Call-by-value:

  • It copies actual value of an argument into function’s formal parameter.
  • The changes made to parameter inside function have no effect on argument.
  • This technique is used in default in programs.
  • The code within a function could not alter arguments that are used for calling function.

Program Plan Intro

void Functions:

  • A function must either return a single or no value.
  • A function that would not return a value is termed as “void” function.
  • The “void” function is been defined in same way as function that would return a value.
  • It implements only subtask for complete problem.
  • If a “void” function is called, formal parameters are substituted with arguments.
  • The statements in function body are executed.
  • The “return” statement specifies value that is been returned.

Call-by-Reference:

  • It is a method for substituting arguments.
  • The argument is substituted for formal parameter.
  • The function call arguments may be a variable.
  • This argument variable is substituted for formal parameter.
  • It is similar to copying of argument variables into function definition body in place of formal parameter.
  • The function body code is been executed once argument is substituted.
  • This code can change argument variable value.
  • The ampersand sign (&) is attached to end of type name in formal parameter list in both function declaration as well as function header definition.

Call-by-value:

  • It copies actual value of an argument into function’s formal parameter.
  • The changes made to parameter inside function have no effect on argument.
  • This technique is used in default in programs.
  • The code within a function could not alter arguments that are used for calling function.

Blurred answer
Students have asked these similar questions
What roles do the parameters and the return statement play in a function definition?
Why would you use a formal parameter to get data into a function when you could use a symbolic constant instead? Explain.
Why is the return statement is required in a function body?

Chapter 5 Solutions

Problem Solving with C++, Student Value Edition