Purchase Solution

Passing parameters

Not what you're looking for?

Ask Custom Question

Give an example of when passing parameters by value as opposed to passing them by reference is a better technique. Now give an example of when passing parameters by reference as opposed to passing them by value is a better technique. For each example explain why you believe that technique is better than the other.

Purchase this Solution

Solution Summary

The expert provides an example when passing parameters by value as opposed to passing them by reference is a better technique.

Solution Preview

Pass by Value

A parameter passed by value is just that - the caller passes a value to the procedure. Pass by value parameters are input only parameters. That is, you can pass them to a procedure but the procedure cannot return values through them.
If we don't want changes made within a function on parameters passed to a function to affect other parts of the program then "pass by value" method is the better technique over "pass by reference"

let's take a look at the following code example:
//include this file for cout
#include <iostream.h>

// square a number and return it
double square(double value)
{
value = value * ...

Purchase this Solution


Free BrainMass Quizzes
Basic Networking Questions

This quiz consists of some basic networking questions.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

C# variables and classes

This quiz contains questions about C# classes and variables.