Create New Post

C MCQs - 11

  1. What is the time complexity of the bubble sort algorithm used in the provided code?
a) O(n)
b) O(n log n)  
c) O(n^2)  
d) O(log n)  

**Answer: c) O(n^2)**
  

103. In the provided code, what is the purpose of the printArray function?

a) It sorts the array using bubble sort.  
b) It searches for an element in the array.  
c) It prints the elements of the array.  
d) It calculates the sum of elements in the array.  

**Answer: c) It prints the elements of the array.**
 

104. Which of the following best describes the purpose of the bubbleSort function in the provided code?

a) It prints the elements of the array.  
b) It searches for an element in the array.  
c) It sorts the array in ascending order using the bubble sort algorithm.  
d) It calculates the sum of elements in the array.  

**Answer: c) It sorts the array in ascending order using the bubble sort algorithm.**
 

105. What will be the output of the following code snippet?


#include <stdio.h>
int main() {
    int arr[5];
    printf("%d\n", arr[0]);
    return 0;
}
 

a) 0  
b) Random garbage value  
c) Compiler error  
d) Segmentation fault  

**Answer: b) Random garbage value**
 

106. In C, what is the purpose of the memset() function?

a) It allocates memory dynamically.  
b) It fills a block of memory with a particular value.  
c) It copies a block of memory to another block.  
d) It deallocates memory.  

**Answer: b) It fills a block of memory with a particular value.**
 

107. What will be the output of the following code?

 
#include <stdio.h>
int main() {
    char str[] = "Hello";
    printf("%c\n", str[4]);
    return 0;
}
 

a) H  
b) e  
c) l  
d) Undefined behavior  

**Answer: d) Undefined behavior**
 

108. Which of the following functions is used to concatenate two strings in C?

a) strcat()  
b) strcmp()  
c) strcpy()  
d) strlen()  

**Answer: a) strcat()**
 

109. What will be the output of the following code?

#include <stdio.h>
int main() {
    int x = 5, y = 10;
    printf("%d\n", x & y);
    return 0;
}


a) 0  
b) 1  
c) 5  
d) 10  

**Answer: a) 0**

110. What is the purpose of the malloc() function in C?

a) It concatenates two strings.  
b) It fills a block of memory with a particular value.  
c) It allocates memory dynamically.  
d) It searches for an element in the array.  

**Answer: c) It allocates memory dynamically.**
 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

86520