A language 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?
View worked solution
Answer: C
To determine the correct option, let's analyze the requirements of the language :
- Array sizes are not known at compile-time: This means the exact memory requirement for these arrays cannot be determined during compilation.
- Efficient use of memory is required: We cannot simply allocate a fixed, worst-case maximum size for every array, as that would waste significant memory.
Let's evaluate the options based on these requirements:
- Option A is incorrect: Static memory allocation binds memory addresses to variables at compile-time. Since the array sizes are unknown during compilation, static allocation cannot be used efficiently.
- Option B is incorrect: Compilers are fully capable of generating code for languages with dynamic features (such as dynamic array sizing or recursion) using runtime environments. An interpreter is not required.
- Option C is correct: Dynamic memory allocation (such as allocating space on the stack at runtime using activation records, or on the heap) allows the program to request the exact amount of memory needed when the array size is determined at runtime. A compiler can generate code to manage this dynamic allocation.
Thus, a compiler using dynamic memory allocation can be written for .
Free practice · Your answers on this page are not saved.
