The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+13 votes

Heap allocation is required for languages.

  1. that support recursion

  2. that support dynamic data structure

  3. that use dynamic scope rules

  4. None of the above

in Compiler Design by Veteran (52.1k points) | 2.1k views

same question asked in 2010

3 Answers

+17 votes
Best answer

Memory is taken from heap for dynamic allocation.

So, option (B) is correct.

by Boss (11k points)
edited by
plz tell meaning of dynamic scope rule

In dynamic scoping, you search in the local function first, then you search in the function that called the local function, then you search in the function that called that function, and so on.

Dynamic scoping is useful as a substitute for globally scoped variables.

why C) is not correct?
by mistake you type B is not correct.

here B is correct
yes sorry now chk
+8 votes

A. false bcoz When a function is called recursively, a stack frame is allocated for each of the recursive call of the function.

B. true bcoz  Heap allocation is needed for dynamic data structures like tree, linked list, etc.

C. false bcoz Dynamic scoping is useful as a substitute for globally scoped variables.

by Active (4.3k points)
globally scope variable not used in heap?

I think Heap is used where dynamic memory allocation usually takes place(memory can be allocate and deallocated at run time or at any time depending upon user's requirement).

global and static variables are stored in data in this segment is initialized by the kernel  before the program starts executing.all uninitialized global variables and static variables are initialized to zero .

recursion is also supported by heap allocation.

in c we can also use global variable in heap explicitely with malloc() and free().

Hello rajoramanoj

explain your reasoning behind option C.

I'm unable to relate dynamic scoping with global variables. As per my knowledge Dynamic scoping is no where related to heap are. It's related to stack although.
Clear all doubt
0 votes
(B ) heap allocation dynamic data structure reason (dynamic data structure -: those data structure whose size inc or dec at runtime so we don't know the actual size e.g stack,queue.
by Junior (847 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,845 questions
54,783 answers
80,433 users