Memory Allocation in C language MCQs

@T-Bone

This question paper focuses on the "Memory Allocation" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

This question paper focuses on the "Memory Allocation" of the C programming. These Multiple Choice Questions (mcq) should be practiced to improve the C programming skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.

Questions

1. What is the return type of malloc() or calloc()?

Mark the correct option

2. Which function is used to delete the allocated memory space?

Mark the correct option

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

Mark the correct option

4. Which of the following is/are true

Mark the correct option

5. Which of the following is true?

Mark the correct option

6. Which languages necessarily need heap allocation in the run time environment?

Mark the correct option

7. Which of the following statement is correct prototype of the malloc() function in c ?

Mark the correct option

8. Specify the 2 library functions to dynamically allocate memory?

Mark the correct option

9. malloc() returns a float pointer if memory is allocated for storing float's and a double pointer if memory is allocated for storing double's. A.

Mark the correct option

10. malloc() allocates memory from the heap and not from the stack.

Mark the correct option

11. What is the output of this program? #include <stdio.h> #include <stdlib.h> int main() { int i, numbers[1]; numbers[0] = 15; free(numbers); printf("Stored integers are "); printf("numbers[%d] = %d ", 0, numbers[0]); return 0; }

Mark the correct option

12. What is the output of this program? #include <stdio.h> #include <stdlib.h> int main() { int *j = (int*)malloc(4 * sizeof(int)); *j = 15; free(j); printf("%d", *j); return 0; }

Mark the correct option

13. What is the output of this program? #include <stdio.h> #include <stdlib.h> int main() { int *numbers = (int*)calloc(4, sizeof(int)); numbers[0] = 2; free(numbers); printf("Stored integers are "); printf("numbers[%d] = %d ", 0, numbers[0]); return 0; }

Mark the correct option

14. What is the output of this program? #include <stdio.h> void main() { int *ptr = (int *)malloc(sizeof(int)); *ptr = 10; free(ptr); p = 5; printf("%d", ptr); }

Mark the correct option

15. What is the output of this program? #include <stdio.h> #include <stdlib.h> int main() { int i; char *ptr; char *fun(); ptr = fun(); printf(" %s", ptr); return 0; } char *fun() { char disk[30]; strcpy(disk, "letsfindcourse"); printf("%s ",disk); return disk; }

Mark the correct option

16. What is the output of this program? #include <stdio.h> #include <stdlib.h> int main() { int *p; p = (int *)malloc(40); printf("%d", sizeof(p)); free(p); return 0; }

Mark the correct option

17. What is the output of this program? #include <stdio.h> #include <stdlib.h> int main() { struct test { int i; float f; char c; }; struct test *ptr; ptr = (struct test *)malloc(sizeof(struct test)); ptr ->f = 2.5f; printf("%f", ptr->f); return 0; }

Mark the correct option

18. Which statment is true about the given code ? #include <stdio.h> #include <stdlib.h> int main() { int *a[5]; a = (int*) malloc(sizeof(int)*5); free(a); return 0; }

Mark the correct option

19. What is the Error of this program? #include <stdio.h> #include <stdlib.h> int main() { char *ptr; *ptr = (char)malloc(30); strcpy(ptr, "RAM"); printf("%s", ptr); free(ptr); return 0; }

Mark the correct option

20. How will you free the memory allocated by the following program? #include <stdio.h> #include <stdlib.h> #define MAXROW 2 #define MAXCOL 3 int main() { int **p, i, j; p = (int **) malloc(MAXROW * sizeof(int*)); return 0; }

Mark the correct option

21. Consider the following program, where are i, j and k are stored in memory? #include <stdio.h> #include <stdlib.h> int i; int main() { int j; int *k = (int *) malloc (sizeof(int)); }

Mark the correct option

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

Mark the correct option

23. Point out the error in the following program. #include <stdio.h> #include <stdlib.h> int main() { char *ptr; *ptr = (char)malloc(30); strcpy(ptr, "RAM"); printf("%s", ptr); free(ptr); return 0; }

Mark the correct option

24. Where does the uninitialized data gets stored in memory?

Mark the correct option

25. malloc() returns a NULL if it fails to allocate the requested memory.

Mark the correct option

26. If malloc() successfully allocates memory it returns the number of bytes it has allocated.

Mark the correct option

27. Can I increase the size of dynamically allocated array?

Mark the correct option

28. Can we increase the size of statically allocated array?

Mark the correct option

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

Mark the correct option

30. What is the output of this program? #include <stdio.h> #include <stdlib.h> int main() { struct test { int i; float f; char c; }; struct test *ptr; ptr = (struct test *)malloc(sizeof(struct test)); ptr ->f = 5.5f; printf("%f", ptr->f); return 0; }

Mark the correct option

31. Local variables are stored in an area called ___________

Mark the correct option

32. Choose the statement which is incorrect with respect to dynamic memory allocation.

Mark the correct option

33. The type of linked list in which the node does not contain any pointer or reference to the previous node:

Mark the correct option

34. The advantage of using linked lists over arrays is that ________

Mark the correct option

35. Which of the following is an example for non linear data type?

Mark the correct option

36. If malloc() successfully allocates memory it returns the number of bytes it has allocated. # include<stdio.h> #include<stdlib.h> void fun(int *a) { a = (int*)malloc(sizeof(int)); } int main() { int *p; fun(p); *p = 6; printf("%dn",*p); return(0); }

Mark the correct option

37. During preprocessing, the code #include gets replaced by the contents of the file stdio.h. Which is true?

Mark the correct option

38. Why to use fflush() library function?

Mark the correct option

39. Why is calloc() function used for?

Mark the correct option

40. Which is the correct sequence of compilation process?

Mark the correct option