FDS MCQ Question Bank Unit 1 To 4
FDS MCQ Question Bank Unit 1 To 4
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
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;
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)
#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;
}