Question

In: Computer Science

What is pass-by-reference? What is pass-by-value? What is a memory leak? What happens if the function...

What is pass-by-reference?

What is pass-by-value?

What is a memory leak?

What happens if the function makes a change to that received array and why?

Functions in C++ can return only one data item (e.g., variable) using the return statement and they also cannot return arrays. There is, however, another way to "return" more than one item from a function without using the return statement. Can you explain how and why?

How are arrays represented in memory?

What is the difference between a pointer variable and a reference variable?

What are assigned to pointers?

What are assigned to reference variables? Can they both be reassigned? If not, can you identify which one cannot be reassigned and explain why? If they can both be reassgined, can you explain why?

What is the difference between an array and a python list?

Solutions

Expert Solution

* What is pass-by-reference?

When a parameter is passed by reference, the caller and the callee use the same variable for the parameter. If the callee modifies the parameter variable, the effect is visible to the caller's variable.

* What is pass-by-value?

When a parameter is passed by value, the caller and callee have two independent variables with the same value. If the callee modifies the parameter variable, the effect is not visible to the caller.

* What is a memory leak?

when programmers create a memory in heap and forget to delete it then memory leak will occurs.
The Memory leaks mainly big problem for the programs like daemons and servers which will never terminate.

*What happens if the function makes a change to that received array and why?

- There are two uses of arrays those are to hold numeric data like test scores and character strings holding.

- There are two methods for counting no of cells of an array those are storing a count in a separate variable and marking the end of the data with a special character.

So in both cases the details of array processing can easily obscure the actual logic of a program and the processing a set of scores or a character string.

So It is often best to treat an array as an abstract data type with a set of allowed operations on the array which are performed by functional modules.

Let us return to our score ex to read and store scores in an array and then print them, except that we now wish to use functions to read and print the array. so the function makes a change to that received array.


How are arrays represented in memory?

- The elements of array are stored in consecutive memory locations
- an array of 10 32-bit integer variables with indices 0 through 9 may be stored as 10 words at memory addresses 2000, 2004, 2008, ... 2036 so that the element with index i has the address 2000 + 4 × i
- Arrays are useful mostly because the element indices can be computed at run time.
- The memory address of the first element of an array is called first address or foundation address

* What is the difference between a pointer variable and a reference variable?

- A pointer can be re-assigned
- A reference cannot, and must be assigned at initialization
- A pointer has its own memory address and size on the stack
- reference shares the same memory address but takes up space on the stack.
- pointers to pointers to pointers offering extra levels of indirection
- references only offer one level of indirection

* What are assigned to pointers?  

In normal assignments we can involve the pointers and the pointer is an alias for its target so if the target is undefined or disassociated the pointer acquires the same status as the target.

* What are assigned to reference variables? Can they both be reassigned? If not, can you identify which one cannot be reassigned and explain why? If they can both be reassgined, can you explain why?  

The reference variable can do and do not refer to an object and it can refer to different objects at different times.
We need to say that a variable does not refer to an object. we do this by assigning null to the variable.

* What is the difference between an array and a python list?

- Arrays and lists are both used in Python to store data but they dont serve same.

- They both can be used to store any data type and they both can be indexed and iterated but common things are in between the two.

- The main difference between a list and an array is the functions which we perform to them.


Related Solutions

Give one example that will show that pass by value, pass by Reference, pass by name,...
Give one example that will show that pass by value, pass by Reference, pass by name, pass by value result are all different.
What is a good reference for Why prostatitis and infection happens? The reference need to be...
What is a good reference for Why prostatitis and infection happens? The reference need to be after 2016.
Java uses pass by value to pass parameters to a method. What are the important differences...
Java uses pass by value to pass parameters to a method. What are the important differences between passing a value of variables of primitive data types and passing arrays? Use a specific example to explain
[6 marks] Java uses pass by value to pass parameters to a method. What are the...
[6 marks] Java uses pass by value to pass parameters to a method. What are the important differences between passing a value of variables of primitive data types and passing arrays? Use a specific example to explain
What happens to a memory that has already been encoded (say, that one gets a shock...
What happens to a memory that has already been encoded (say, that one gets a shock when stepping into a white room), if it is reactivated, and then protein synthesis is blocked (i.e. during reconsolidation)?
What happens to memory as we age? How might this affect our quality of life?
What happens to memory as we age? How might this affect our quality of life?
What is a “void” method? What does “pass by value” mean? What is the scope of...
What is a “void” method? What does “pass by value” mean? What is the scope of a variable? What does it mean to say that a method is overloaded?
Sketch, find the reference angle, and the exact function value of the following: 1. Sec -225°...
Sketch, find the reference angle, and the exact function value of the following: 1. Sec -225° 2. Sin -45°                                                              3. Cos -120°                                                             4. Cos 495° 5. Tan 480° 6. Sin -450° 7. Sec 315°
1. What happens if one solute can pass through the membrane, but another cannot? 2. How...
1. What happens if one solute can pass through the membrane, but another cannot? 2. How do semi-permeable membranes and the processes of diffusion and osmosis contribute to homeostasis in cells?
What happens when the signs of the function in IVT are the same? Is it true...
What happens when the signs of the function in IVT are the same? Is it true that they don’t have any roots? Show an example
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT