Question

In: Computer Science

We learned that when calling subprograms or functions that we can pass data to the subprogram...

We learned that when calling subprograms or functions that we can pass data to the subprogram or function by ‘value’ or by ‘reference’. Describe what each approach is, how it works and what the potential security disadvantage is when passing parameters by reference.

Solutions

Expert Solution

When you pass parameters to a function, you can do so in two ways:

  1. Pass by value
  2. Pass by reference

When you pass a parameter to a function by value, then a copy of the variable is made in memory. When you access or modify the variable in the function, then only the copy of the variable is modified. The original variable is left untouched.

When you pass a parameter to a function by reference, you pass the memory address of the function, so it is the same variable being passed to the function. So when you modify the variable from the function the original value of the variable is changed too.  

When passing parameters by reference you are allowing the original value of the variable to be modififed, which in some cases might lead to a function changing the value even when the function is not intended to do so. The programmer will need to take special care to not accidentally modify the variable.

If you like the answer, please support by upvoting it. And if you have any doubts regarding this, please comment in the comment section, I am sure to help.


Related Solutions

We can build a heap by repeatedly calling the insert function to insert the elements into...
We can build a heap by repeatedly calling the insert function to insert the elements into the heap. Here is pseudocode: buildHeap(A) h = new empty heap   for each element e in A       h.insert(e)             What is the Big-O runtime of this version of buildHeap? Justify your answer.
Suppose we are using this data to attempt to pass a quality test in order to...
Suppose we are using this data to attempt to pass a quality test in order to market this material. 2.58     2.51     4.04     6.43     1.58     4.32     2.2       4.19     4.79     6.2       1.52     1.38     3.87     4.54     5.12     5.15 5.5       5.92     4.56     2.46     6.9       1.47     2.11     2.32 6.75 5.84     8.8       7.4       4.72     3.62     2.46     8.75 a....
This week, we learned that there are four levels of abstraction of a data model. They...
This week, we learned that there are four levels of abstraction of a data model. They are contextual, conceptual, logical, and physical. Briefly explain each level with a focus on the differences between them. When working on the final project for this course, many students go directly to the physical model. What would you say to these students? Why would you say so?
This week we delved into the features of Access. We learned about importing and exporting data...
This week we delved into the features of Access. We learned about importing and exporting data to and from other applications. Please write your own scenario, either from a previous experience you have had or from your own imagination, where it was necessary to import and export data from one application to another in the Microsoft Office Suite.
We have learned hypothesis tests for the mean (when population variance is known and when it...
We have learned hypothesis tests for the mean (when population variance is known and when it is unknown) for a percentage to see if the means of two sets of data are the same goodness of fit test test for independence For each type give a brief example. You do not have to solve the problem you give. Try to come up with a problem on your own
We have learned hypothesis tests for the mean (when population variance is known and when it...
We have learned hypothesis tests for the mean (when population variance is known and when it is unknown) for a percentage to see if the means of two sets of data are the same goodness of fit test test for independence For each type give a brief example. You do not have to solve the problem you give.
DATA STRUCTURES   What is returned when calling this method with the singly list contains (1,5,5,7,8)   public...
DATA STRUCTURES   What is returned when calling this method with the singly list contains (1,5,5,7,8)   public static int m1(SinglyList  list1) {   if(list1.size()!=2) return list1.removeFirst()+m1(list1);      return s; }
Code and document the following functions using NON-RECURSIVE ITERATION only. Test the functions by calling them...
Code and document the following functions using NON-RECURSIVE ITERATION only. Test the functions by calling them from a simple interactive main() function using a menu, with different values used to select the choice of function. Overall, you should have one C program (call it Lab1.c) containing one main() function and 5 other functions, where the functions are called based on an interactive user menu. The program should contain a loop that permits users to enter a new choice of function...
Write a python program that has subprograms (functions) nested 3 deep. Each subprogram should reference variables...
Write a python program that has subprograms (functions) nested 3 deep. Each subprogram should reference variables defined in each of its enclosing subprograms. To submit this program, copy/paste the program and a screenshot of your output when you run it. Use comments liberally so that we can understand your work! You can run JavaScript wherever you prefer, but it is available on repl.it.
what can be learned from data driven decision making
what can be learned from data driven decision making
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT