Question

In: Computer Science

1. Int abc; 2. Int def = 8; 3. abc = def; ➢ Describe the procedure...

1. Int abc; 2. Int def = 8; 3. abc = def; ➢ Describe the procedure how much memory will be allocated when these three lines of codes will execute. ➢ Describe what will happened after execution of each of these line of code in term of memory allocation and data storage.

Solutions

Expert Solution

int abc;

int def=8;

abc=def;

a) in the first statement memory (4 bytes for int) will be allocated to abc .

in the second statement memory(4 bytes for int) will be allocated to def first then the pointer holding the variable

def(say ptr) will be allocated the value 8.

in the third statement a copy of def will be passed to abc and it will assigned value 8

so overall there will be 8 bytes of memory allocation in this process.

b) after the execution of first statement a pointer(say p1) to a memory of 4 byte will be allocated in the memory stack. since there is no value allocated to it right now so it will store some garbage value in it

after the execution of the second statement a pointer(say p2) to a memory of 4 byte will be allocated in the memory stack and now we have a value assigned to it so the value will be passed to the pointer .

after the execution of the third statement the pointer P1 will be assigned the value at the address of pointer P2

i,e *p1=*p2 here * means the value at the address.

so finally pointer P1 is pointing to a memory location of 4 byte having value 8 in it and similarly P2 is pointing to a

memory location of 4 byte having a value 8 in it


Related Solutions

Qno.1 Part(A). IN jAVA if 1.Int abc; 2. Int def = 8; 3. abc = def;...
Qno.1 Part(A). IN jAVA if 1.Int abc; 2. Int def = 8; 3. abc = def; ➢ Describe the procedure how much memory will be allocated when these three lines of codes will execute. ➢ Describe what will happened after execution of each of these line of code in term of memory allocation and data storage Qno.1 Part(B) A capacitor is constructed from two conductive metal plates 30cm x 50cm which are spaced 6mm apart from each other, and uses...
Use pseudocode to describe an algorithm for the procedure: int[][] find_pairs( int array[], int value ).
Use pseudocode to describe an algorithm for the procedure: int[][] find_pairs( int array[], int value ). Given a sorted array of distinct integers and a single integer value, find all pairs of indexes in the list whose product is equal to the value. Return the index pairs on the same row of a two-dimensional array. Note, m will be the number of rows and total number of pairs found, while 2 will be the number of columns along every row...
Why is 1 example of my code failing? def current_player_score(score_one: int, score_two: int,current_player: str) -> int:...
Why is 1 example of my code failing? def current_player_score(score_one: int, score_two: int,current_player: str) -> int: """Return <score_one> if the <current_player> represents player one, or <score_two> if the <current_player> represents player two. >>> current_player_score(2, 4, "Player one") 2 >>> current_player_score(2, 3, "Player two") 3 """ if current_player == PLAYER_ONE: return score_one return score_two
5. (20%) Suppose we have an array int a [8] = {1, 2, 3, 5, 6};...
5. (20%) Suppose we have an array int a [8] = {1, 2, 3, 5, 6}; and we also have a linked list L of 5 entries 1 -> 2 -> 3 -> 5 -> 6, where 1 is the first in the linked list L, followed by 2 etc. We want to put a new item 4 between 3 and 5 in the array a and in the linked list L (a) Explain in plain English how you do...
Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function: int BBOX(int...
Suppose A is (10, 2, 5, 9, 1, 8, 2, 4). Consider the function: int BBOX(int n, int k)             if (n <= 0) return 0;             else if (A[n] < k) return (1+ 2*BBOX(n-1,k+1));             else return BBOX(n-1,k-2);             Find BBOX(8, 5)
EXPLAIN ANS PLEASE: PYTHON 1. s = 'abc' print(s[0:] + s[-2:2] + s[:1]) 2. def mirrorOnWheels(s):...
EXPLAIN ANS PLEASE: PYTHON 1. s = 'abc' print(s[0:] + s[-2:2] + s[:1]) 2. def mirrorOnWheels(s): prev = 0 for current in range(1, len(s) - 1): prev = current - 1 next = current + 1 if s[prev] == s[next]: break else: continue return 0 return prev s = 'Good decision!' print(mirrorOnWheels(s)) 3. mixture = {1:[1, 2, 0], 2:[2, 0, 1], 0:[0, 1, 2]} print(mixture[2][2]) 4. noOddHeroes = [] heroes = ['superman', 'batman', 'aquaman'] for hero in heroes: if len(hero)...
Fibonacci (C++) Generate 1st n fibonacci numbers: std::vector<int> v = {1, 1, 2, 3, 5, 8,...
Fibonacci (C++) Generate 1st n fibonacci numbers: std::vector<int> v = {1, 1, 2, 3, 5, 8, 13, 21}; auto w = fibonacci(8); Note: NO LOOPS ALLOWED Thanks!
QUESTION 5 What is printed? int[] aArray = {1, 2, 3, 4}; int[] bArray = {5,...
QUESTION 5 What is printed? int[] aArray = {1, 2, 3, 4}; int[] bArray = {5, 6, 7, 8}; bArray = aArray; System.out.print(bArray[2]); 1 points    QUESTION 6 What is printed? public static void main(String[] args) { int[] aArray = { 1, 2, 3, 4 }; System.out.print(aArray[2]); int i = aMeth(aArray); System.out.print(i + "" + aArray[2]); } public static int aMeth(int[] iArray) { for (int i = 0; i < iArray.length; i++) { iArray[i]++; } int[] bArray = { 5,...
def largest_rectangle_in_matrix(matrix: List[List[int]]) -> int: """ Returns the area of the largest rectangle in <matrix>. The...
def largest_rectangle_in_matrix(matrix: List[List[int]]) -> int: """ Returns the area of the largest rectangle in <matrix>. The area of a rectangle is defined as the number of 1's that it contains. Again, you MUST make use of <largest_rectangle_at_position> here. If you managed to code largest_rectangle_at_position correctly, this function should be very easy to implement. Similarly, do not modify the input matrix. Precondition: <matrix> will only contain the integers 1 and 0. >>> case1 = [[1, 0, 1, 0, 0], ... [1,...
what is the output? int main ( ) { int a = 3, b= 2, c=...
what is the output? int main ( ) { int a = 3, b= 2, c= 1, d, e, f, g; d = a&b;    e = a | c; f = a >> 1, g = a << 1; cout << “d= “ << d << “ e = “ << e << “ f = “ << f << “g = “ << g << endl; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT