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