in Compiler Design edited by
4,662 views
17 votes
17 votes

A language $L$ allows declaration of arrays whose sizes are not known during compilation. It is required to make efficient use of memory. Which one of the following is true?

  1. A compiler using static memory allocation can be written for $L$
  2. A compiler cannot be written for $L$; an interpreter must be used
  3. A compiler using dynamic memory allocation can be written for $L$
  4. None of the above
in Compiler Design edited by
4.7k views

2 Answers

26 votes
26 votes
Best answer

C.

Using dynamic memory allocation, memory will be allocated to array at runtime.

edited by

4 Comments

@suchithreddy

Each time a function is called, it needs some stack space, so that space is allocated — the activation record. It is known at compile time how big the activation record is for a given procedure (more or less; variable length arrays complicate things), but it isn't known how much space will be needed in total because the sequence of function calls isn't known — especially with recursion.

https://stackoverflow.com/questions/34120001/how-is-the-amount-of-memory-in-stack-area-determined-at-compile-time-only

3
3

@Arjun Sir 

Only DATA segment part of the program like static variables, string literals etc. are allocated during compile time. For heap area, how much memory to be allocated is also determined at run time.

if we do not know how much memory will be allocated in heap in compile time then how can we allocate static variables in heap in compile time? pls pls clear my confusion...

0
0

@debasree88 static or global variables are allocated in static area of the memory during compile time not in heap area.Read arjun sir comments above .

0
0
0 votes
0 votes
A compiler using dynamic memory allocation can be written for the language."

Dynamic memory allocation allows the allocation of memory at runtime, which is useful when the size of arrays is not known during compilation. This allows for more flexibility in managing memory and handling variable-sized arrays. Static memory allocation, on the other hand, is not suitable for cases where array sizes are not known at compile time.
Answer:

Related questions