100% found this document useful (3 votes)
5K views

FDS MCQ Question Bank Unit 1 To 4

The document contains 20 multiple choice questions related to C programming. The questions cover topics like arrays, pointers, functions, loops, data types, operators, and more. Sample questions include output of code snippets, time complexity of sorting algorithms, valid C statements, and identifying errors in code.

Uploaded by

Ufyfivig
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
5K views

FDS MCQ Question Bank Unit 1 To 4

The document contains 20 multiple choice questions related to C programming. The questions cover topics like arrays, pointers, functions, loops, data types, operators, and more. Sample questions include output of code snippets, time complexity of sorting algorithms, valid C statements, and identifying errors in code.

Uploaded by

Ufyfivig
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 15

Sr.

Questions
No.
What is the output of this program?
void main()
{
int a[8] = {1,2,3,4,5};
printf("%d", a[5]);
1 }

A. 5
B. 6
C. 0
D. Garbage Value
What is the output of this program? (Assume that base address of ‘a’ is 1000 and size of integer
is 32 bit)
#include<stdio.h<>
int main()
{
int a[10];
a++;
2 printf("%u", a);
return 0;
}

A. 1004
B. 1002
C. 1008
D. Lvalue Required

What is the output of following program


#include<stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
3 union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d, %d, %d", u.ch[0], u.ch[1], u.i);
return 0;
}

a. 3,2,515
b. 515,2,3
c. 3,2,5
d. 515,515,4
What will be the output of the following C code?
1. #include <stdio.h>
2. int main()
3. {
4. int i =10;
5. void*p =&i;
4 6. printf("%d\n",(int)*p);
7. return0;
8. }
a) Compile time error
b) Segmentation fault/runtime crash
c) 10
d) Undefined behaviour
1. #include <stdio.h>
2. int main()
3. {
4. int i = 10;
5. void *p = &i;
5 6. printf("%f\n", *(float*)p);
7. return 0;
8. }
a) Compile time error
b) Undefined behaviour
c) 10
d) 0.000000
Six files Fl, F2, F3, F4, F5 and F6 have 100,200,50,80, 120, 150 number of records
respectively. In what order should they be stored so as to optimize access time? Assume each
file is accessed with the same frequency
6 a. Fl, F2, F3, F4, F5, F6
b. F2, F6, F5, Fl, F4, F3
c. F3, F4, FI, F5, F6, F2
d. Ordering is immaterial as all files are accessed with the same frequency
Which is not the output function:
A) printf();
B) puts();
7
C) puchar();
D) putch();
E) None of these
The C code ‘for ( ; ; )’ represents an infinite loop. It can be terminated by
A) break
8 B) exit(0)
C) abort()
D) terminate
Which is not the selective control flow statement:
A) While
9 B) If
C) Switch-case
D) if-else
The concept of order (Big O) is important because
a. it can be used to decide the best algorithm that solves a given problem
b. it determines the maximum size of a problem that can be solved in a given system, in a
10
given amount of time
c. all of the above
d. none of these
A function which invokes itself repeatedly until some condition is satisfied is called a
___________ function.
A) Recursive
11
B) System
C) Library
D) None of these
Randomized quicksort is an extension of quicksort where the pivot is chosen randomly. What
is the worst case complexity of sorting n numbers using randomized quicksort?
e. O(n^2)
12
f. O(nLogn)
g. O(n)
a. O(n!)
Array is an example of _______ type memory allocation.
13
A. Compile time
B. Run time
Which is not the selective control flow statement:
a. while
14 b. if
c. Switch-case
d. if-else
c = (n) ?a : b; can be rewritten as exp1 ? exp2 : exp3;

A. if(n){c = a;}else{c = b;}


15
B. if(!n){c = a;}else{c = b;}
C. if(n){c = b;}else{c = a;}
D. None of the above
A one dimensional array A has indices 1....75. Each element is a string and takes up three
memory words. The array is stored at location 1120 decimal. The starting address of A[49] is

16 A. 1264
B. 1164
C. 1167
D. 1267
If the two strings are identical, then strcmp() function returns
A. -1
17 B. 1
C. 0
D. None
18 Let x be an array. Which of the following operations are illegal?
I. ++x
II.x+1
III.x++
IV. x*2
A. I and II
B. I, II and III
C. II and III
D. I, III and IV
How many times it will execute printf() statement?
#include<stdio.h>
void main()
{
int j=1;
while(j<=255)
{
19 printf(“%d\n”,j)
j++;
}
}
A) 0 times
B) 254 times
C) 255 times
D) 256 times
What will the output of following program ?
#include<stdio.h>
void main( )
{
int i=0;
for ( ; i ;)
20
printf(“Hello Friends”);
}
A) Prints Nothing
B) Raise an error
C) Will go in continuous loop
D) Hello Friends
What will be the output of following program:
#include<stdio.h>
void main()
{
int a=1,b=10;
21 printf(“\n %d %d %d %d %d”,++a, a++, --a, a--, ++a+b);
}
A) 2 0 0 2 12
B) 2 2 2 2 12
C) 2 3 2 1 12
D) 1 2 1 0 11
22 main()
{
int a=5;
int b=10;
{
int a=2;
a++;
b++;
}
printf("%d%d" ,a,b);
}
What will be output of program?
A) 5 10
B) 5 11
C) 6 11
D) 6 10
Assume that the algorithms considered here sort the input sequences in ascending order. If the
input is already in ascending order, which of the following are TRUE ?
I. Quicksort runs in Θ(n2) time
II. Bubblesort runs in Θ(n2) time
III. Mergesort runs in Θ(n) time
23
IV. Insertion sort runs in Θ(n) time
a. I and II only
b. I and III only
c. II and IV only
d. I and IV only
Which of the following sorting algorithms does not have a worst case running time of O(n^2)?
a. Quick sort
24 b. Bubble sort
c. Merge sort
d. Insertion sort
What will be output when you will execute following c code?

#include<stdio.h>
void main(){
int a=100;
if(a>10)
printf("M.S. Dhoni");
else if(a>20)
printf("M.E.K Hussey+");
else if(a>30)
25 printf("A.B. de villiers");
}
A) M.S. Dhoni
B) A.B. de villiers
C) M.S Dhoni
M.E.K Hussey
A.B. de Villiers
D) Compilation error: More than one
conditions are true
E) one of the above
In the call by reference we pass:
A) Value of the variable
26 B) Address of variable
C) Both value and address
D) None of these
27 Which of the following algorithm is not stable?
a. Quick sort
b. Bubble sort
c. Merge sort
d. Insertion sort
Add the missing statement for the following program to print 35.
main()
{
int j,*ptr;
*ptr=35;
__________;
28
printf(“\n%d”,j);
}
A) ptr =&j
B) j=*ptr
C) j =ptr
D) j =&ptr
What is the time complexity of Binary Search algorithm?
a. O(n^2)
b. O(2^n)
29
c. O(log n).
d. O(2n)

hat will be the out of t program ?

#include<stdio.h>

int main()
{
char p[] = "%d";
p[1] = 'c';
30
printf(p, 65);
return 0;
}

a. A
b. C
c. 65
d. Compile time error.
Give the output of following code ?
#include<stdio.h>
int main( )
{
int x=3;
float y=3.0;
if(x = = y)
31 printf(“ x and y are equal”);
else
printf(“x and y are not equal”);
}
A) x and y are equal
B) x and y are not equal
C) x and y are same
D) None of above
Which is an indirection operator among the following?
a. &
32 b. *
c. ->
d. .
Consider the statement
int val[2][4]={1,2,3,4,5,6,7,8};
4 will be the value of
33 A) val[0][4]
B) val[0][3]
C) val[1][1]
D) None of the above
printf(“%u”,&a);
The output of this statement is:
A) Value of a
34
B) Address of a
C) Both
D) None of these.
35
FILE is of ___________.
A) int type
36 B) char type
C) struct type
D) None
Determine the output
void main()
{
int const *p=5;
printf(“%d”, ++(*p));
37
}
A) 6
B) 5
C) Garbage value
D) Compiler Error
Which is the file opening mode:
A) a
38 B) b
C) c
D) d
39 What will be the output of following code:

#include<stdio.h>
void main()
{
int *p,**q, ***r, i=5;
p=&i;
q=&p;
r=&q;
printf(“\n %i %d %u %d %u %u %d “, i, *p, *q, **q, *r, **r,***r);
}
A) value of i, value of i ,address of p, value of p, address of q, value of q, value of i
B) value of i, value of i ,address of p, value of i, address of q, value of q, value of r
C) value of i, value of i ,address of p, value of i, address of q, value of q, value of i
D) error: undefined identifier %i.
What will be the output of following code:
#include<stdio.h>
void strcpy1(char [], char[]);
void strcpy2(char*, char*);
void main()
{
char string1[10] = “MODERN”;
char string2[10],string3[10];
strcpy1(string1,string2);
printf(“Copied String is : %s”, string2);
strcpy2(string3,string1);
printf(“Copied String is : %s”, string3);
40 }
void strcpy1(char s1[10], char s2[10])
{
strcpy(s2,s1);
}
void strcpy2(char* s1, char* s2)
{
strcpy(s2,s1);
}
A) MODERN MODERN
B) MODERN garbage value
C) garbage value garbage value
D) garbage value MODERN
int *P = (int *)malloc(2); gives:
A) an error
41 B) assigns base address of allocated memory block to P
C) assigns 2 to P
D) assigns int to P
The main measure for efficiency algorithm are-
A) Processor and Memory
42 B) Complexity and Capacity
C) Data and Space
D) Time and space
Which of the following data structure is not a non-linear data structure?
A) Arrays
43 B) tree
C) graph
D) none
44 In total, how many times inner for loop will get
executed?
#include<stdio.h>
void main()
{
int i,j;
clrscr();
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
if(i==0&&j==0)
break;
printf(“i = %d”,i);
}
printf(“ i = %d”,i);
getch();
}
A) 9
B) 12
C) 3
D) 4
What will be the output of the following C code?

1. #include <stdio.h>
2. int *f();
3. int main()
4. {
5. int *p = f();
6. printf("%d\n", *p);
7. }
8. int *f()
45
9. {
10. int *j = (int*)malloc(sizeof(int));
11. *j = 10;
12. return j;
13. }
a)10
b)Compile time error
c) Segmentation fault/runtime crash since pointer to local variable is returned
d) Undefined behaviour
What is the output of this C code?
int main()
{
int *ptr, a = 10;
ptr = &a;
*ptr += 1;
46
printf("%d,%d/n", *ptr, a);
}
a. 10,10
b. 10,11
c. 11,10
d. 11,11
47 What will be the output of the program ?
#include<stdio.h>
int main()
{
char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"};
int i;
char *t;
t = names[3];
names[3] = names[4];
names[4] = t;
for(i=0; i<=4; i++)
printf("%s,", names[i]);
return 0;
}

a. Suresh, Siva, Sona, Baiju, Ritu


b. Suresh, Siva, Sona, Ritu, Baiju
c. Suresh, Siva, Baiju, Sona, Ritu
d. Suresh, Siva, Ritu, Sona, Baiju
What is the function of the mode ‘ w+’?
a) create text file for writing, discard previous contents if any
48 b) create text file for write&read, discard previous contents if any
c) create text file for writing, do not discard previous contents if any
d) create text file for update, do not discard previous contents if any
#include<stdio.h>
voidf(int*p, int*q)
{
p = q;
*p = 2;
}
inti = 0, j = 1;
intmain()
{
49
f(&i, &j);
printf("%d %d n", i, j);
getchar();
return0;
}
a. 2 2
b. 2 1
c. 0 1
d. 0 2
50 What is time complexity of fun()?
intfun(intn)
{
intcount = 0;
for(inti = n; i > 0; i /= 2)
for(intj = 0; j < i; j++)
count += 1;
returncount;
}
a. O(n^2)
b. O(nLogn)
c. O(n)
d. O(nLognLogn)
Choose correct option
1. Stack is a Ephemeral Data Structure.
2. Queue is not a Ephemeral Data Structure.
3. Stack and Queue are non-linear Data Structures
4. Array is a Dynamic Data Structure.
51
A) all 1. 2. 3. and 4. are correct
B) only 1. and 2. are correct
C) only 2. and 3. are false
D) all 1. 2. 3. and 4. are false
Calculate time complexity required for following code:
for(i=0;i<n;i++)
for(j=0;j<n-1;j++)
for(k=0;k<n-2;k++)
if(a[j]<a[k])
52
printf(“\n DONE…..”);
A) O(n)
B) O(n2)
C) O(n3)
D) O(n+n(n-1)+n(n-1)(n-2))
In best case analysis of algorithm, ___ of an algorithm is calculated
A) Big Oh
53 B) Big Omega
C) Big Theta
D) none
Big Oh is___
A) Asymptotic lower bound
54 B) Asymptotic upper bound
C) Frequency count
D) Rate of growth of a function
Naming convention for variable is followed in company because ____________.
A) it enhances the efficiency
55 B) it enhances readability
C) it allows to work without conflicts
D) all of the above
What data structure can be used in recursive call to a function?
A) Linked List
56 B) Queue
C) Stack
D) Tree
For 5 numbers, find out the time complexity for bubble
sort for worst case
A) 5
57
B) 10
C) 20
D) 25
58 The time complexity of a quick sort algorithm which makes use of median, found by an O(n)
algorithm, as
pivot element is
A) O(nloglogn)
B) O(nlogn)
C) O(n 2 )
D) O(n)
For merging two sorted lists of size m and n into sorted list of size m+n, we require
comparisons of
A) O(m)
59
B) O(m+n)
C) O(n)
D) O(logm + logn)
Which of the following sorting algorithm is of divide and conquer type?
A) Bubble sort
60 B) Insertion sort
C) Selection sort
D) Merge Sort
Partition and exchange sort is ……..
A) Tree sort
61 B) Heap sort
C) Bubble sort
D) Quick Sort
Complete following given passes required for insertion sort.
pass #1- 55 11 77 22 99 66
pass #2- ______________
pass #3- ______________
pass #4- ______________
pass #5- ______________
pass #6- 11 22 55 66 77 99
A) pass #2- 55 11 22 66 77 99
pass #3- 11 55 22 66 77 99
pass #4- 11 22 55 66 77 99
pass #5- 11 22 66 55 77 99
62 B) pass #2- 11 55 22 77 66 99
pass #3- 11 22 55 77 66 99
pass #4- 11 22 55 66 77 99
pass #5- 11 22 55 77 66 99
C) pass #2- 11 55 22 77 66 99
pass #3- 11 55 22 77 66 99
pass #4- 11 22 55 77 66 99
pass #5- 11 22 55 66 77 99
D) pass #2- 11 55 77 22 99 66
pass #3- 11 55 77 22 99 66
pass #4- 11 22 55 77 99 66
pass #5- 11 22 55 77 99 66
Complexity of linear search algorithm is .........
A) O(n)
63 B) O(logn)
C) O(n2)
D) O(n logn)
64 A sorting technique is called stable if it
A) Takes O(nlogn) times
B) Uses divide-and-conquer paradigm
C) Maintains the relative order of occurrence of non-distinct element
D) Takes O(n) space
Which of the following is not a stable sorting algorithm?
A) Insertion sort
65 B) Quick sort
C) Bubble sort
D) Merge sort
Which of the following is not an in-place sorting algorithm?
A) Insertion sort
66 B) Selection sort
C) Bubble sort
D) Merge sort
Binary search algorithm can be applied to ____
A) Sorted Binary Tree
67 B) Sorted linear array
C) Pointer array
D) All of the above
The complexity of bubble sort algorithm is …..
A) O(n)
68 B) O(logn)
C) O(n^2)
D) O(n logn)
The recurrence relation capturing the optimal time of the Tower of Hanoi problem with n discs
is.
a. T(n) = 2T(n – 2) + 2
69
b. T(n) = 2T(n – 1) + n
c. T(n) = 2T(n/2) + 1
d. T(n) = 2T(n – 1) + 1
To determine the efficiency of an algorithm the time factor is measured by:
a. Counting micro seconds
70 b. Counting number of key operations
c. Counting number of statements
d. Counting kilobytes of algorithm
Indicate constant time complexity in terms of Big-O notation
e. O(n^2)
f. O(Logn)
71
g. O(n)
h. O(1)

Space complexity of an algorithm is the maximum amount of _______ required by it during


execution.
a. Time
72
b. Operations
c. Memory space
d. None of the above
In the analysis of algorithms, what plays an important role?
a. Text Analysis
73 b. Growth factor
c. Time
d. None of the above
To verify whether a function grows faster or slower than the other function, we have some
asymptotic or mathematical notations, which is_________.
a. Big Omega Ω (f)
74
b. Big Theta θ (f)
c. Big Oh O (f)
d. All of the above
What is the time complexity of adding an item in front of a LinkedList
O(n^2)
O(Logn)
75
O(n)
O(1)

Time required to merge two sorted lists of size m and n, is


a. Ο(m | n)
76 b. Ο(m + n)
c. Ο(m log n)
d. Ο(n log m)
Quick sort algorithm is an example of
a. Greedy approach
77 b. Improved binary search
c. Dynamic Programming
d. Divide and conquer
The number of comparisons required to sort 5, 1, 6, 2, 4 in ascending order using Bubble Sort
is
a. 6
78
b. 4
c. 5
d. Both B&C
The sorting technique where array to be sorted is partitioned again and again in such a way that
all elements less than or equal to partitioning element appear before it and those which are
greater appear after it, is called ..............
79 a. Quick sort
b. Bubble sort
c. Merge sort
d. Insertion sort
The average number of key comparisons done in successful sequential search in a list of length
n is ..............
a. log n
80
b. (n-1)/2
c. n/2
d. (n+1)/2
81 Following is a-------sort.
int min;
for(int j=0; j<arr.length-1; j++)
{
min = j;
for(int k=j+1; k<=arr.length-1; k++)
{
if(arr[k]< arr[min])
min = k;
}
int temp = arr[min];
arr[min]= arr[j];
arr[j]= temp;
}
a. Selection
b. Bubble sort
c. Improved bubble sort
d. Insertion sort

Ms. D. A. Bhanage Mrs. Sampada Kulkarni Ms. S. M. Jagtap


NBA Criteria III Incharge Module Co-ordinator Subject In-charge

You might also like