Top

Memory Allocation

1.

What function should be used to free the memory allocated by calloc() ?

Answer: C

free(); function should be used to free the memory allocated by calloc().

Enter details here

2.

Can I increase the size of dynamically allocated array?

Answer: A

 

Use realloc(variable_name, value);

Enter details here

Answer: C

No answer description available for this question.

Enter details here

4.

Among 4 header files, which should be included to use the memory allocation functions like malloc(), calloc(), realloc() and free()?

Answer: B

#include is a header filer, which contains the inbuilt functions for all memory allocation functions.

Enter details here

5.

Local variables are stored in an area called ___________

Answer: D

Local variables are stored in an area called stack. Global variables, static variables and program instructions are stored in the permanent storage area. The memory space between these two regions is known a heap.

Enter details here

6.

Can I increase the size of dynamically allocated array?

Answer: A

Use realloc(variable_name, value);

Enter details here

7.

When we dynamically allocate memory is there any way to free memory during run time?

Answer: A

Using free()

Enter details here

8.

What is the Error of this program?

#include 
#include  
int main()

{
     char *ptr;
     *ptr = (char)malloc(30);
     strcpy(ptr, "RAM");
     printf("%s", ptr);
     free(ptr);
     return 0;
}

 

Answer: B

None

Enter details here

Answer: D

None

Enter details here

10.

How many bytes of memory will the following code reserve?

#include
#include

int main()
{
    int *p;
    p = (int *)malloc(256 * 256);
    if(p == NULL)
        printf("Allocation failed");
    return 0;
}

 

Answer: B

Hence 256*256 = 65536 is passed to malloc() function which can allocate upto 65535. So the memory allocation will be failed in 16 bit platform (Turbo C in DOS).

If you compile the same program in 32 bit platform like Linux (GCC Compiler) it may allocate the required memory

Enter details here

Loading…
Tags: Memory Allocation Questions and Answers || Memory Allocation MCQ Questions and Answers || Memory Allocation GK Questions and Answers || Memory Allocation GK MCQ Questions || Memory Allocation Multiple Choice Questions and Answers || Memory Allocation GK || GK on Memory Allocation || C Programming Questions and Answers || C Programming MCQ Questions and Answers || C Programming GK Questions and Answers || GK on C Programming