Skip to main content

Shorting Objective question for c language

1. Which of the following is the correct syntax for using the bubble sort algorithm in C?

a. bubbleSort(int arr[], int n);

b. void bubbleSort(int *arr, int n);

c. int *bubbleSort(int arr[], int n);

d. bubbleSort(int *arr);

Answer: b. void bubbleSort(int *arr, int n);


2.Which sorting algorithm has the best average-case time complexity in C?

a. Bubble Sort

b. Insertion Sort

c. Merge Sort

d. Selection Sort

Answer: c. Merge Sort


3.Which sorting algorithm is not an in-place sorting algorithm in C?

a. Bubble Sort

b. Heap Sort

c. Insertion Sort

d. Quick Sort

Answer: b. Heap Sort


4.Which of the following is the correct time complexity of the Quick Sort algorithm in C?

a. O(n)

b. O(nlogn)

c. O(n^2)

d. O(logn)

Answer: b. O(nlogn)


5.Which of the following is an example of a stable sorting algorithm in C?

a. Bubble Sort

b. Insertion Sort

c. Quick Sort

d. Shell Sort

Answer: b. Insertion

6.Which of the following is not a valid variable type in C?

a) int

b) float

c) char

d) decimal

Answer: d) decimal


7.Which of the following is not a valid C keyword?

a) if

b) while

c) start

d) break

Answer: c) start


8.Which of the following is not a valid way to declare a function in C?

a) int myFunction();

b) void myFunction(void);

c) myFunction(int);

d) int myFunction(int);

Answer: c) myFunction(int);


9.What is the output of the following code?

#include <stdio.h>

int main()

{

   int x = 10, y = 5;

   x = x + y;

   y = x - y;

   x = x - y;

   printf("x = %d, y = %d", x, y);

   return 0;

}

a) x = 5, y = 10

b) x = 10, y = 5

c) x = 15, y = 5

d) x = 5, y = 15


Answer: b) x = 10, y = 5


10.What is the output of the following code?

#include <stdio.h>

int main()

{

   int x = 10, y = 5;

   int *p1 = &x, *p2 = &y;

   *p1 = *p2;

   printf("x = %d, y = %d", x, y);

   return 0;

}

a) x = 5, y = 10

b) x = 10, y = 5

c) x = 5, y = 5

d) x = 10, y = 10


Answer: c) x =A 5, y = 5


11.Which of the following is not a valid way to initialize an array in C?

a) int arr[] = {1, 2, 3};

b) int arr[3] = {1, 2, 3};

c) int arr[3] = {1, 2};

d) int arr[3] = {0};

Answer: c) int arr[3] = {1, 2};


12.Which of the following is not a valid way to declare a pointer in C?

a) int *p;

b) float *p;

c) char *p;

d) int **p;

Answer: d) int **p;


13.What is the output of the following code?

#include <stdio.h>

int main()

{

   int arr[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

   printf("%d", arr[1][2]);

   return 0;

}

a) 1

b) 2

c) 6

d) 8


Answer: c) 6

14.Which of the following is a sorting algorithm in C?

a) binary search

b) merge sort

c) breadth-first search

d) depth-first search

Answer: b) merge sort


15.Which of the following is not a stable sorting algorithm in C?

a) bubble sort

b) selection sort

c) quick sort

d) insertion sort

Answer: c) quick sort


16.Which of the following sorting algorithms has a worst-case time complexity of O(n^2) in C?

a) bubble sort

b) merge sort

c) heap sort

d) radix sort

Answer: a) bubble sort


17.Which of the following is a comparison-based sorting algorithm in C?

a) counting sort

b) bucket sort

c) quick sort

d) radix sort

Answer: c) quick sort


18.Which of the following is an in-place sorting algorithm in C?

a) quick sort

b) merge sort

c) heap sort

d) insertion sort

Answer: a) quick sort


19.Which of the following is a stable sorting algorithm in C?

a) quick sort

b) heap sort

c) insertion sort

d) shell sort

Answer: c) insertion sort


20.Which of the following is an external sorting algorithm in C?

a) quick sort

b) merge sort

c) bubble sort

d) selection sort

Answer: b) merge sort


21.Which of the following is not a comparison-based sorting algorithm in C?

a) counting sort

b) quick sort

c) heap sort

d) insertion sort

Answer: a) counting sort


22.Which of the following is a recursive sorting algorithm in C?

a) bubble sort

b) selection sort

c) insertion sort

d) merge sort

Answer: d) merge sort


23.Which of the following sorting algorithms is typically used for sorting linked lists in C?

a) bubble sort

b) selection sort

c) insertion sort

d) merge sort

Answer: d) merge sort

Comments