1.when we create a dynamic array the area of memory used is called
a. runtime area
b. usable memory area
c. heap
d. stack
Kindly cherry-pick up the language applicable (one of C/C++/Java)
The answer to the question is at the end, after explaining the different types of memory-allocations.
Arrays can be declared in three ways :
On the stack, locally in functions :
Following is the common manner of declaring a function-local array, on a stack.
void foo()
{
int arr[] = {123, 53, 21, 89};
}
On the heap, dyamically :
For C :
void foo()
{
int *arr = (int*) malloc(4 * sizeof(int));
arr[0] = 123;
arr[1] = 53;
arr[2] = 21;
arr[3] = 89;
}
For C++ :
void foo()
{
int *arr = new int[4];
arr[0] = 123;
arr[1] = 53;
arr[2] = 21;
arr[3] = 89;
}
For Java :
void foo()
{
int arr[] = new int[4];
arr[0] = 123;
arr[1] = 53;
arr[2] = 21;
arr[3] = 89;
}
All other variables :
Everything else uses the data segment of the process/program.
Thus, the correct option is :
c. heap
Get Answers For Free
Most questions answered within 1 hours.