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