-4

True or False: When a function is called, the calling program suspends until
the function completes.

True or False: When you call a function with a list as a parameter, you could
change the original calling program’s list from within the function

True or False: When you call a function with a dictionary as a parameter, you could change the original calling program’s dictionary from within the function.

Im very fuzzy on these questions and what they mean, could someone help explain these?

2 Answers2

0

1.True the original program will stop and going to run the function. It will back to the place where it stop and start to execute the next line command after function done.

2.False call by value. it wont change the original variable's value.

3.True call by pointer or call by reference.

0
  1. Sometime yes and sometimes no. It depends whether you are calling it synchronously or asynchronously, see this answer for the distinction: Asynchronous vs synchronous execution, what does it really mean?
  2. In most cases yes, because you are just passing by reference, i.e you are passing the location in memory of the param you are passing. However, you can also pass by value, i.e passing a copy of the object. See this question for more detail: What's the difference between passing by reference vs. passing by value?
  3. same answer as your previous question. Whether you are passing an integer, string, array, list, dictionary, it doesn't matter, it all depends on whether you are passing by reference or by value. Which one of these happens by default depends on which programming language you use. You can determine which one is happening pretty easily with some experimentation: Define a function with a dictionary variable, add a key/value pair call another function with the dict as a param, and modify it in the called function, then print it out in the calling function once the called function has returned. If it has been modified, you know you are passing by reference. If it has the original key/value you set in the caller and is not modified, you know you are passing by value.
Community
  • 1
  • 1