In: Computer Science
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?
* 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.