273
94.3k

340+ Data Structure and Algorithms (DSA) Solved MCQs

These multiple-choice questions (MCQs) are designed to enhance your knowledge and understanding in the following areas: Computer Science Engineering (CSE) , Information Technology Engineering (IT) , Electronics and Communication Engineering , Common Topics in Competitive and Entrance exams .

101.

A sort which compares adjacent elements in a list and switches wherever necessary is _______

A. insertion sort
B. bubble sort
C. selection sort
D. none of these
Answer» B. bubble sort
102.

Which of the following sorting method is the slowest?

A. quick sort
B. merge sort
C. bubble sort
D. none of these
Answer» C. bubble sort
103.

Consider that n elements are to be sorted.The worst case complexity of bubble sort is____

A. o(1)
B. o(log2n)
C. o(n)
D. o(n2)
Answer» D. o(n2)
104.

In bubble sort,for a file of size n,after p iterations number of records in proper position is____

A. n-p
B. n-p+1
C. n-p+2
D. p
Answer» A. n-p
105.

In bubble sort,for a file of size n,during each pth pass the number of last records left out are____

A. n-p
B. n-p+1
C. p
D. p-1
Answer» D. p-1
106.

Given a file size n the number of times a given file is passed through in bubble sort is____

A. n2
B. n-1
C. nlogn
D. logn
Answer» A. n2
107.

Total number of comparision in bubble sort is____

A. o(nlogn)
B. o(n2)
C. o(n)
D. none of these
Answer» B. o(n2)
108.

A sort which iteratively passes through a list to exchange the first element with any element less than it and then repeats with a new first element is called

A. insertion sort
B. selection sort
C. bubble sort
D. merge sort
Answer» B. selection sort
109.

The selection sort is basically a method of repeated

A. interchange
B. searching
C. position adjustment
D. none of these
Answer» C. position adjustment
110.

In selection sort of n elements,how many times is the swp function called in the complete execution of the algorithm?

A. 1
B. n-1
C. n(n-1)/2
D. none of these
Answer» B. n-1
111.

If two string are identical then strcmp() function returns____

A. -1
B. 1
C. 0
D. none of these
Answer» C. 0
112.

How will you print \n on screen?

A. printf("\\n");
B. printf(\\\n\);
C. echo\\\\n;
D. printf("\\\\n");
Answer» A. printf("\\n");
113.

Following function is used to find the first occurrence of given string in another string

A. strchar
B. strnset
C. strstr
D. strrchr
Answer» D. strrchr
114.

Which of the following is more appropriate for reading a multi_word string?

A. printf
B. scanf
C. put
D. gets
Answer» D. gets
115.

What will be the output of the following code? Int main(){printf("Hello","Word\n");return 0;}

A. hello
B. hello world
C. world
D. none of these
Answer» A. hello
116.

What will be the output of the following code? Int main(){char str[9]="My Computer";printf("%s\n",str);return 0;}

A. mycompute
B. syntax error
C. runtime error
D. none of these
Answer» B. syntax error
117.

Pointer is a___________

A. a keyword used to create a variable
B. a variable that stores the address of some instruction
C. a variable that stores the address of some other variable
D. all of the above
Answer» C. a variable that stores the address of some other variable
118.

____operator is used to get the value stored at address stored in pointer variable

A. *
B. &
C. dot
D. +
Answer» A. *
119.

Which of the following statement is true about char ****a ?

A. a is pointer to a pointer to a pointer to char
B. a is pointer to a pointer to a pointer to char
C. a is a pointer to a char pointer
D. a is a pointer to a pointer to a char
Answer» B. a is pointer to a pointer to a pointer to char
120.

Are *ptr++ and ++*ptr are same?

A. no they are not same
B. yes they are one and the same
C. depends upon the value of ptr
D. none of these
Answer» A. no they are not same
121.

What will be the output of the following code? Void main(){int a=10;int *b=&a;int **c=&b;printf("%d %d %d",a,*b,**c);}

A. 10 10 garbage
B. 10 garbage garbage
C. 10 10 10
D. syntax error
Answer» C. 10 10 10
122.

Which of the following is a collection of different data type elements?

A. array
B. structure
C. string
D. all of the above
Answer» B. structure
123.

What is the similarity between structure,union and enum?

A. all of them let you define new values
B. all of them let you define new pointers
C. all of them let you define new structure
D. all of them let you define new data types
Answer» D. all of them let you define new data types
124.

Which of the following can not be a structure member?

A. another structure
B. array
C. function
D. none of these
Answer» C. function
125.

The members of the union are accessed by____

A. dot operator
B. pointer -> operator
C. both a and b
D. none of these
Answer» C. both a and b
126.

a-> is systematically correct if_____

A. a is a pointer to a structure in which b is a field
B. a and b are structure
C. a is a structure and b is a pointer to a structure
D. a is a pointer to a structure and b is a structure
Answer» A. a is a pointer to a structure in which b is a field
127.

How many bits are absolutely necessary to store an ASCII character ?

A. 7
B. 8
C. 15
D. 16
Answer» A. 7
128.

The result of 0001 1010 / 0001 0101 is

A. 0001 1111
B. 1111 0001
C. 0001 0000
D. none of these
Answer» A. 0001 1111
129.

The result of 0001 1010 & 0000 1000 is ___

A. 0001 1111
B. 1111 0001
C. 0000 1000
D. none of these
Answer» C. 0000 1000
130.

The result of 0001 1010 ~ 0100 0011 is

A. 0101 1001
B. 1010 0100
C. 0000 0010
D. none of these
Answer» B. 1010 0100
131.

The result of 0001 1010^0001 0000 is____

A. 0101 1001
B. 1010 0100
C. 0000 0010
D. none of these
Answer» C. 0000 0010
132.

The result of 0001 1010 << 2 is____

A. 0101 1100
B. 0110 1000
C. 0001 1110
D. none of these
Answer» B. 0110 1000
133.

The result of 0001 1010 >>2 is____

A. 0101 1100
B. 0010 1110
C. 0000 0110
D. none of these
Answer» C. 0000 0110
134.

The most significant bit is lost in following operation

A. <<
B. >>
C. &
D. /
Answer» A. <<
135.

The result of i)true AND false II)false or false

A. i)is true and ii)is true
B. i)is true and ii)is false
C. i)is false and ii)is true
D. i)is false and ii)is false
Answer» D. i)is false and ii)is false
136.

What will be output if you will compile and execute the following c code? #include<stdio.h>
int main(){
int i=320;
char *ptr=(char *)&i;
printf("%d",*ptr); return 0;
}

A. 320
B. 1
C. 64
D. none of the above
Answer» C. 64
137.

What will be output if you will compile and execute the following c code? #include<stdio.h>
#define x 5+2
int main(){
int i;
i=x*x*x;
printf("%d",i); return 0;
}

A. 343
B. 27
C. 133
D. compiler error
Answer» B. 27
138.

What will be output if you will compile and execute the following c code? #include<stdio.h>
int main(){
char c=125;
c=c+10;
printf("%d",c); return 0;
}

A. 135
B. +inf
C. -121
D. -8
Answer» C. -121
139.

What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){
float a=5.2;
if(a==5.2)
printf("Equal");
else if(a<5.2)
printf("Less than");
else
printf("Greater than"); return 0;
}

A. equal
B. less than
C. greater than
D. compiler error
Answer» B. less than
140.

What will be output if you will compile and execute the following c code? #include<stdio.h>
int main(){
int i=4,x;
x=++i + ++i + ++i;
printf("%d",x); return 0;
}

A. 21
B. 18
C. 12
D. compiler error
Answer» A. 21
141.

What will be output if you will compile and execute the following c code? #include<stdio.h>
int main(){
int a=2;
if(a==2){
a=~a+2<<1;
printf("%d",a);
}
else{
break;
} return 0;
}

A. it will print nothing
B. -3
C. -2
D. compiler error
Answer» D. compiler error
142.

What will be output if you will compile and execute the following c code? #include<stdio.h>
int main(){
int a=10;
printf("%d %d %d",a,a++,++a); return 0;
}

A. 12 11 11
B. 12 10 10
C. 11 11 12
D. 10 10 12
Answer» A. 12 11 11
143.

What will be output if you will compile and execute the following c code? #include<stdio.h>
int main(){
char *str="Hello world";
printf("%d",printf("%s",str)); return 0;
}

A. 10hello world
B. 11hello world
C. hello world12
D. hello world13
Answer» D. hello world13
144.

What will be output if you will compile and execute the following c code?
#include <stdio.h>
#include <string.h>
int main(){
char *str=NULL;
strcpy(str,"cquestionbank");
printf("%s",str); return 0;
}

A. cquestionbank
B. cquestionbank\\0
C. (null)
D. it will print nothing
Answer» C. (null)
145.

#include <stdio.h>
#include <string.h>
int main(){
int i=0;
for(;i<=2;)
printf(" %d",++i); return 0;
}

A. 0 1 2 3
B. 0 1 2
C. 1 2 3
D. compiler error
Answer» C. 1 2 3
146.

What will be output if you will compile and execute the following c code? #include<stdio.h>
int main(){
int x;
for(x=1;x<=5;x++);
printf("%d",x); return 0;
}

A. 4
B. 5
C. 6
D. compiler error
Answer» C. 6
147.

What will be output if you will compile and execute the following c code? #include<stdio.h>
int main(){
printf("%d",sizeof(5.2)); return 0;
}

A. 2
B. 4
C. 8
D. 10
Answer» C. 8
148.

What will be output if you will compile and execute the following c code?
#include <stdio.h>
#include <string.h>
int main(){
char c='\08';
printf("%d",c); return 0;
}

A. 8
B. \8\
C. 9
D. compiler error
Answer» D. compiler error
149.

What will be output if you will compile and execute the following c code? #include<stdio.h>
#define call(x,y) x##y
int main(){
int x=5,y=10,xy=20;
printf("%d",xy+call(x,y)); return 0;
}

A. 35
B. 510
C. 15
D. 40
Answer» D. 40
150.

What will be output if you will compile and execute the following c code? #include<stdio.h>
int * call();
int main(){ int *ptr;
ptr=call();
printf("%d",*ptr); return 0;
} int * call(){
int a=25;
a++;
return &a;
}

A. 25
B. 26
C. any adress
D. garbage value
Answer» D. garbage value

Done Studing? Take A Test.

Great job completing your study session! Now it's time to put your knowledge to the test. Challenge yourself, see how much you've learned, and identify areas for improvement. Don’t worry, this is all part of the journey to mastery. Ready for the next step? Take a quiz to solidify what you've just studied.