502 views
2 votes
2 votes
MSQ


Consider execution of the following C code for different cases:

printf(“%d”,&a);

Consider the following statements. Which among these are TRUE:

  1. Will print Logical Address in case of Local Variables, as they are static, compiled before runtime, and compiler generates LAS.
  2. Will print Logical Address in case of Global Variables, as they are static, compiled before runtime, and compiler generates LAS.
  3. Will print Physical Address in case of variables Dynamically allocated during the runtime, like malloc()
  4. Will print Logical Address in case of variables Dynamically allocated during the runtime, like malloc()

1 Answer

1 votes
1 votes

Answer: ‘a’,’b’ and ‘d’
 

#include <stdio.h>

int main() {
    
    int a=33;
    int b = (int*)malloc(sizeof(int));
    b=37;
    if(fork()==0)
    {
    printf("Child\n");
    printf("a is %d and address is %d   \t",a,&a);
    printf("b is %d and address is %d",b,&b);
    printf("\n\n");
    }
    else
    {
    b=b+1;
    a=a+1;
    printf("Parent\n");
    printf("a is %d and address is %d   \t",a,&a);
    printf("b is %d and address is %d",b,&b);
    printf("\n\n");
    }
    

    return 0;
}

 

Related questions

0 votes
0 votes
1 answer
1
Raj Singh 1 asked Jan 3, 2019
5,014 views
Physical address is(A) The logical address added by the value in re-locatable registers(B) Re location register – logical address(C) Re location address + relocation re...
1 votes
1 votes
1 answer
2
Richa Sharma asked Jan 22, 2016
2,628 views
Represent the sentence "We are IT students" in physical memory if page size is 5 characters and the entries in page table are-061527310Assume physical memory size to be 5...
0 votes
0 votes
1 answer
3