Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
Question
Book Icon
Chapter 5.2, Problem 10STE
Program Plan Intro

void Functions:

  • A function must either return a single or no value at all.
  • 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 corresponding argument is substituted for formal parameter.
  • The argument for a function call might 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 code in function body is 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 the actual value of an argument into function’s formal parameter.
  • The changes made to parameter inside function have no effect on argument.
  • This method is used in default in programs.
  • The code within a function could not alter arguments used for calling function.

Blurred answer
Students have asked these similar questions
Write the definition of a void function that takes as input two parameters of type int, say sum and testScore the function updates the value of sum by adding the value of testScore. The new value of sum is reflected in the calling environment.
In C++ Write the definition of a void function that has one double parameter and changes the sign of the parameter (if it is negative it becomes positive, and if it is positive it becomes negative)
PYTHON  You Define a Function Part 1: Write a function that takes in one or two input parameters and returns an output. The function should return the output of a one-line expression. Write at least three test cases for your function in the docstring.  Make sure your function has just one line of code   Part 2: Write the same function as a lambda function.

Chapter 5 Solutions

Problem Solving with C++ (10th Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning