MCQOPTIONS
Saved Bookmarks
This section includes 22 Mcqs, each offering curated multiple-choice questions to sharpen your C Interview knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
The following C code is an example of __________ |
| A. | Memory leak |
| B. | Dangling pointer |
| C. | Static memory allocation |
| D. | Linked listView Answer |
| Answer» C. Static memory allocation | |
| 2. |
The free() function frees the memory state pointed to by a pointer and returns ___________ |
| A. | the same pointer |
| B. | the memory address |
| C. | no value |
| D. | an integer value |
| Answer» D. an integer value | |
| 3. |
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 |
| Answer» E. | |
| 4. |
What will happens if the statement free(a) is removed in the following C code? |
| A. | is removed in the following C code? a) Error |
| B. | Memory leak |
| C. | Dangling pointer arises |
| D. | 200 is printed as outputView Answer |
| Answer» C. Dangling pointer arises | |
| 5. |
In the function malloc(), each byte of allocated space is initialized to zero. |
| A. | True |
| B. | False |
| Answer» C. | |
| 6. |
What will be the output of the following C code if the input entered as first and second number is 5 and 6 respectively? |
| A. | 56 |
| B. | Address of the locations where the two numbers are stored |
| C. | 57 |
| D. | ErrorView Answer |
| Answer» E. | |
| 7. |
If the space in memory allocated by malloc is not sufficient, then an allocation fails and returns ___________ |
| A. | NULL pointer |
| B. | Zero |
| C. | Garbage value |
| D. | The number of bytes available |
| Answer» B. Zero | |
| 8. |
Garbage collector frees the programmer from worrying about ___________ |
| A. | Dangling pointers |
| B. | Creating new objects |
| C. | Memory leak |
| D. | Segmentation errors |
| Answer» D. Segmentation errors | |
| 9. |
When the pointer is NULL, then the function realloc is equivalent to the function ___________ |
| A. | malloc |
| B. | calloc |
| C. | free |
| D. | alloc |
| Answer» B. calloc | |
| 10. |
What will be the error (if any) in the following C code? |
| 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);View Answer |
| Answer» D. Error in the statement: free(p);View Answer | |
| 11. |
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)); |
| Answer» E. | |
| 12. |
What will be the output of the following C code if it is executed on a 32 bit processor? |
| A. | 2 |
| B. | 4 |
| C. | 8 |
| D. | Junk valueView Answer |
| Answer» C. 8 | |
| 13. |
The incorrect statement with respect to dangling pointers is ___________ |
| A. | Pointer pointing to non-existent memory location is called dangling pointer |
| B. | When a dynamically allocated pointer references the original memory after it has been freed, a dangling pointer arises |
| C. | If memory leak occurs, it is mandatory that a dangling pointer arises |
| D. | Dangling pointer may result in segmentation faults and potential security risks |
| Answer» E. | |
| 14. |
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 which is used to implement recursive function calls |
| D. | Everything on the heap is anonymous |
| Answer» B. Static variables are stored on the heap | |
| 15. |
is removed, what happens? |
| A. | Error |
| B. | Memory leak |
| C. | Dangling pointer arises |
| D. | 200 is printed as output |
| Answer» C. Dangling pointer arises | |
| 16. |
If malloc() and calloc() are not type casted, the default return type is ___________ |
| A. | void* |
| B. | void** |
| C. | int* |
| D. | char* |
| Answer» D. char* | |
| 17. |
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 |
| Answer» C. Frozen memory | |
| 18. |
Which of the following functions allocates multiple blocks of memory, each block of the same size? |
| A. | malloc() |
| B. | realloc() |
| C. | calloc() |
| D. | free() |
| Answer» B. realloc() | |
| 19. |
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)); |
| Answer» D. x=(int*)malloc(10*sizeof(int)); | |
| 20. |
The number of arguments taken as input which allocating memory dynamically using malloc() is ___________ |
| A. | 0 |
| B. | 1 |
| C. | 2 |
| D. | 3 |
| Answer» E. | |
| 21. |
56 |
| A. | Address of the locations where the two numbers are stored |
| B. | 57 |
| C. | Error |
| Answer» C. Error | |
| 22. |
2 |
| A. | 4 |
| B. | 8 |
| C. | Junk value |
| Answer» C. Junk value | |