The following C code is an example of . . . . . . . .
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
char *p,*q;
p=(char*)malloc(3*sizeof(char));
q=p;
strcpy(p,"hello");
printf("p=%s",p);
printf("q=%s",q);
free(q);
q=NULL;
gets(p);
gets(q);
printf("%s",p);
printf(“%s”,q);
}A. Memory leak
B. Dangling pointer
C. Static memory allocation
D. Linked list
Select an option to see the answer and solution.
If malloc() and calloc() are not type casted, the default return type is . . . . . . . .
A. void*
B. void**
C. int*
D. char*
Select an option to see the answer and solution.
Which of the following functions allocates multiple blocks of memory, each block of the same size?
A. malloc()
B. realloc()
C. calloc()
D. free()
Select an option to see the answer and solution.
A condition where in memory is reserved dynamically but not accessible to any of the programs is called . . . . . . . .
A. Memory leak
B. Dangling pointer
C. Frozen memory
D. Pointer leak
Select an option to see the answer and solution.
Which of the following header files must necessarily be included to use dynamic memory allocation functions?
A. stdlib.h
B. stdio.h
C. memory.h
D. dos.h
Select an option to see the answer and solution.
What will be the error (if any) in the following C code?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *p;
*p = (char)calloc(10);
strcpy(p, "HELLO");
printf("%s", p);
free(p);
return 0;
}A. No error
B. Error in the statement: strcpy(p,"HELLO");
C. Error in the statement: *p=(char)calloc(10);
D. Error in the statement: free(p);
Select an option to see the answer and solution.
What will happens if the statement free(a) is removed in the following C code?
#include<stdio.h>
#include<stdlib.h>
main()
{
int *a;
a=(int*)malloc(sizeof(int));
*a=100;
printf("*a%d",*a);
free(a);
a=(int*)malloc(sizeof(int));
*a=200;
printf("a%p",a);
*a=200;
printf("a%d",*a);
}A. Error
B. Memory leak
C. Dangling pointer arises
D. 200 is printed as output
Select an option to see the answer and solution.
In the function realloc(), if the new size of the memory block is larger than the old size, then the added memory . . . . . . . .
A. is initialized to junk values
B. is initialized to zero
C. results in an error
D. is not initialized
Select an option to see the answer and solution.
What will be the output of the following C code if it is executed on a 32 bit processor?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p;
p = (int *)malloc(20);
printf("%d\n", sizeof(p));
free(p);
return 0;
}Select an option to see the answer and solution.
Garbage collector frees the programmer from worrying about . . . . . . . .
A. Dangling pointers
B. Creating new objects
C. Memory leak
D. Segmentation errors
Select an option to see the answer and solution.
Suppose we have a one dimensional array, named 'x', which contains 10 integers. Which of the following is the correct way to allocate memory dynamically to the array 'x' using malloc()?
A. x=(int*)malloc(10);
B. x=(int*)malloc(10,sizeof(int));
C. x=malloc(int 10,sizeof(int));
D. x=(int*)malloc(10*sizeof(int));
Select an option to see the answer and solution.
Queue data structure works on the principle of . . . . . . . .
A. Last In First Out (LIF0)
B. First In Last Out (FILO)
C. First In First Out (FIFO)
D. Last In Last Out (LILO)
Select an option to see the answer and solution.
Which of the following is an example of static memory allocation?
A. Linked list
B. Stack
C. Queue
D. Array
Select an option to see the answer and solution.
What will be the output of the following C code? (Given that the size of array is 4 and new size of array is 5)
#include<stdio.h>
#include<stdlib.h>
main()
{
int *p,i,a,b;
printf("Enter size of array");
scanf("%d",&a);
p=(int*)malloc(a*sizeof(int));
for(i=0;i<a;i++)
printf("%d\n",i);
printf("Enter new size of array");
scanf("%d",&b);
realloc(p,b);
for(i=0;i<b;i++)
printf("%d\n",i);
free(p);
}A. 1234
12345
B. Error
C. 0123
01234
D. 0123
12345
Select an option to see the answer and solution.
The type of linked list in which the node does not contain any pointer or reference to the previous node is . . . . . . . .
A. Circularly singly linked list
B. Singly linked list
C. Circular doubly linked list
D. Doubly linked list
Select an option to see the answer and solution.
In the function malloc(), each byte of allocated space is initialized to zero.
Select an option to see the answer and solution.
The number of arguments taken as input which allocating memory dynamically using malloc() is . . . . . . . .
Select an option to see the answer and solution.
Choose the statement which is incorrect with respect to dynamic memory allocation.
A. Memory is allocated in a less structured area of memory, known as heap
B. Used for unpredictable memory requirements
C. Execution of the program is faster than that of static memory allocation
D. Allocated memory can be changed during the run time of the program based on the requirement of the program
Select an option to see the answer and solution.
Pick out the correct statement with respect to the heap.
A. Local variables are stored on the heap
B. Static variables are stored on the heap
C. Heap is the data structure that is used to implement recursive function calls
D. Everything on the heap is anonymous
Select an option to see the answer and solution.
The size of both stack and heap remains the same during run time.
Select an option to see the answer and solution.