Question 1 of 25
Hints left: 3
Q1
If malloc() and calloc() are not type casted, the default return type is . . . . . . . .
Q2
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); }
Q3
The advantage of using linked lists over arrays is that . . . . . . . .
Q4
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; }
Q5
The incorrect statement with respect to dangling pointers is . . . . . . . .
Q6
Which of the following is an example of static memory allocation?
Q7
Garbage collector frees the programmer from worrying about . . . . . . . .
Q8
The type of linked list in which the node does not contain any pointer or reference to the previous node is . . . . . . . .
Q9
A condition where in memory is reserved dynamically but not accessible to any of the programs is called . . . . . . . .
Q10
Pick out the correct statement with respect to the heap.
Q11
The size of both stack and heap remains the same during run time.
Q12
In the function realloc(), if the new size of the memory block is larger than the old size, then the added memory . . . . . . . .
Q13
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); }
Q14
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; }
Q15
Which standard library function is used to calculate the length of a string in C?
Q16
What is the purpose of the 'printf' function in C?
Q17
The number of arguments taken as input which allocating memory dynamically using malloc() is . . . . . . . .
Q18
Which of the following header files must necessarily be included to use dynamic memory allocation functions?
Q19
Choose the statement which is incorrect with respect to dynamic memory allocation.
Q20
If the space in memory allocated by malloc is not sufficient, then an allocation fails and returns . . . . . . . .
Q21
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()?
Q22
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); }
Q23
Which of the following functions allocates multiple blocks of memory, each block of the same size?
Q24
Queue data structure works on the principle of . . . . . . . .
Q25
In the function malloc(), each byte of allocated space is initialized to zero.