in Operating System
192 views
1 vote
1 vote

in Operating System
192 views

1 comment

The options are:

a.) Only s1 is true

b.) only s2 is true

c.) both s1 and s2 are true

d.) Neither is true
0
0

2 Answers

3 votes
3 votes
Best answer

Both statements S1 and S2 are true.
 

X points to a block of 10 integer space which is in the heap, and X is stored in stack.

selected by
2 votes
2 votes

Answer: Option (c)

Explanation: The above line is attempting to dynamically allocate space for 10 integers and then stores the pointer to the starting (base) address of the allocated memory in the integer pointer x. 

We know that local variables in a program are allocated memory on the stack. Assuming that this line of code was written inside some function F( ), the variable x would be stored in the Activation Record of F( ) on the stack.

On the other hand, the dynamically allocated memory for the 10 integers would be obtained from the heap memory with the help of malloc( ). This means that the variable x is present in the stack, whereas the actual memory that it points to (equal to the space occupied by 10 integers), is allocated on the heap.

Therefore, both statments s1 and s2 are true and hence (c) should be the correct option.

Related questions