C++ and Data Structures MCQs
C++ and Data Structures MCQs
4)If a,b,c are integer variables with values 1,2,3 respectively, then what is the value of the
expression
!((a+5)<(b+c))
a)0 b)6 c)5 d)1
ans-1
6)Construct a logical expression to check whether x is largest among three numbers x,y,z
a)x>y&&x>z b)!(x<=y||x<=z) c)x>y,z d)both a and b
ans-d
Q24) Flowcharts can show errors in ____ which is not readily visible in the other charts.
A) Arithmetic operations
B) Logic
C) Code
D) All of these
Ans. (B)
JSPM's
Jayawantrao Sawant College Of Engineering, Hadapsar,Pune-28
Department of Information Technology
{}
b) int main(intargc,char *argv[])
{}
c) int main(int *argc,char *argv)
{}
d) int main()
{int *argc,char *argv}
Ans D
6) How to call a function without using the function name to send parameters?
a) typedefs
b) Function pointer
c) Both (a) and (b)
d) None of the mentioned
Answer:b
Answer:d
#include <stdio.h>
void first()
{
printf("Hello World");
}
void main()
{
void *ptr() = first;
ptr++
ptr();
}
Answer:c
a) 10
b) 20
c) Sytax error
d) Runtime error
a. C
b. Fortron
c. Pascal
d. Both b&c ans:d
18)main()
{
Int a=5;
Ptr=&a;
Printf(“%d”,++*ptr);
a) 0
b) 1
c) 2
d) 3
ans:1
20) The no. Of argument use in realloc is
a) 0
b) 1
c) 2
d) 3
ans:c
21) the function is use in dynamic deallocation is
a) Destroy()
b) Delet()
c) Free
d) Remove()
ans:c
d) Invalid
ans:a
26) Given int a[5][5];identify the correct expression ,yielding the starting element.
a) *a[0]
b) **a
c) a[0][0]
d) all of these
ans:d
ans:b
29) main()
{
Inta[5]={-2,-1,3,4,5}
Int*b;
b=&a[2];
}
Then value of b[-1] is:
a) 4
b) 3
c) -1
d) -2
ans:c
30)identify invalid pointer oprator
a) &
b) >>
c) *
d) None of these
ans:b
35)How does compiler differentiate address of operator from bitwise AND operator?
a)by using the number of operands and the position of operands
b)by seeing the declarations
c)both options a and b
d)by using the value of the operand
44)Given the declaration double prec[5]; the address of element prec[2]is obtained
a)&prec[2]
b)prec+2
c)both options a and b
d)*(prec+2)
#include <stdio.h>
int mul(int a, int b, int c)
{
return a * b * c;
}
void main()
{
int (*function_pointer)(int, int, int);
function_pointer = mul;
printf("The product of three numbers is:%d",
function_pointer(2, 3, 4));
}
Answer:a
#include <stdio.h>
int mul(int a, int b, int c)
{
return a * b * c;
}
void main()
{
int (function_pointer)(int, int, int);
function_pointer = mul;
printf("The product of three numbers is:%d",
function_pointer(2, 3, 4));
}
Answer:b
#include <stdio.h>
void f(int (*x)(int));
int myfoo(int);
int (*fooptr)(int);
int ((*foo(int)))(int);
int main()
{
fooptr = foo(0);
fooptr(10);
}
int ((*foo(int i)))(int)
{
return myfoo;
}
int myfoo(int i)
{
printf("%d\n", i + 1);
}
a) 10
b) 11
c) Compile time error
d) Undefined behaviour
Answer:b
Answer:b
55. Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0;?
a) int *ptr = &a;
b) int *ptr = &a – &a;
c) int *ptr = a – a;
d) All of the mentioned
Answer:a
#include <stdio.h>
int x = 0;
void main()
{
int *ptr = &x;
printf("%p\n", ptr);
x++;
printf("%p\n ", ptr);
}
a) Same address
b) Different address
c) Compile time error
d) Varies
Answer:a
#include <stdio.h>
int x = 0;
void main()
{
int *const ptr = &x;
printf("%p\n", ptr);
ptr++;
printf("%p\n ", ptr);
}
a) 0 1
b) Compile time error
c) 0xbfd605e8 0xbfd605ec
d) 0xbfd605e8 0xbfd605e8
Answer:b
#include <stdio.h>
void main()
{
int x = 0;
int *ptr = &x;
printf("%p\n", ptr);
ptr++;
printf("%p\n ", ptr);
}
a) 0xbfd605e8 0xbfd605ec
b) 0xbfd605e8 0cbfd60520
c) 0xbfd605e8 0xbfd605e9
d) Run time error
Answer:a
#include <stdio.h>
void main()
{
int x = 0;
int *ptr = &5;
printf("%p\n", ptr);
}
a) 5
b) Address of 5
c) Nothing
d) Compile time error
Answer:d
#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
**m = 6;
printf("%d\n", k);
}
a) 5
b) Compile time error
c) 6
d) Junk
Answer:c
#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int *r = &p;
printf("%d", (**r));
}
a) 1
b) Compile time error
c) Address of a
d) Junk value
Answer:b
#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int **r = &p;
printf("%p %p", *r, a);
}
Answer:c
63. How many number of pointer (*) does C have against a pointer variable declaration?
a) 7
b) 127
c) 255
d) No limits.
Answer:d
#include <stdio.h>
int main()
{
int a = 1, b = 2, c = 3;
int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c;
int **sptr = &ptr1; //-Ref
*sptr = ptr2;
}
a) ptr1 points to a
b) ptr1 points to b
c) sptr points to ptr2
d) None of the mentioned
Answer:b
#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int **r = &p;
printf("%p %p", *r, a);
}
Answer:c
66. What substitution should be made to //-Ref such that ptr1 points to variable C?
#include <stdio.h>
int main()
{
int a = 1, b = 2, c = 3;
int *ptr1 = &a;
int **sptr = &ptr1;
//-Ref
}
a) *sptr = &c;
b) **sptr = &c;
c) *ptr1 = &c;
d) None of the mentioned.
Answer:a
Answer:d
#include <stdio.h>
int main()
{
int a = 10;
int **c -= &&a;
}
Answer:b
#include <stdio.h>
void main()
{
int a[3] = {1, 2, 3};
int *p = a;
int *r = &p;
printf("%d", (**r));
}
a) 1
b) Compile time error
c) Address of a
d) Junk value
Answer:b
#include <stdio.h>
int main()
{
char *str = "This" //Line 1
char *ptr = "Program\n"; //Line 2
str = ptr; //Line 3
printf("%s, %s\n", str, ptr); //Line 4
}
a) Memory holding “this” is cleared at line 3
b) Memory holding “this” loses its reference at line 3
c) You cannot assign pointer like in Line 3
d) Output will be This, Program
Answer:b
71. What type initialization is needed for the segment “ptr[3] = ’3′;” to work?
a) char *ptr = “Hello!”;
b) char ptr[] = “Hello!”;
c) Both (a) and (b)
d) None of the mentioned
Answer:b
73. The syntax for constant pointer to address (i.e., fixed pointer address) is:
#include <stdio.h>
int add(int a, int b)
{
return a + b;
}
int main()
{
int (*fn_ptr)(int, int);
fn_ptr = add;
printf("The sum of two numbers is: %d", (int)fn_ptr(2, 3));
}
Answer:d
75. The correct way to declare and assign a function pointer is done by:
(Assuming the function to be assigned is “int multi(int, int);”)
a) int (*fn_ptr)(int, int) = multi;
b) int *fn_ptr(int, int) = multi;
c) int *fn_ptr(int, int) = &multi;
d) Both (b) & (c)
Answer:a
76. Calling a function f with a an array variable a[3] where a is an array, is equivalent to
a) f(a[3])
b) f(*(a + 3))
c) f(3[a])
d) All of the mentioned
Answer:d
#include <stdio.h>
void f(char *k)
{
k++;
k[2] = 'm';
}
void main()
{
char s[] = "hello";
f(s);
printf("%c\n", *s);
}
a) h
b) e
c) m
d) o;
Answer:a
#include <stdio.h>
void main()
{
char s[] = "hello";
s++;
printf("%c\n", *s);
}
#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student m;
struct student *s = &m;
s->c = "hello";
printf("%s", s->c);
}
a) hello
b) Run time error
c) Nothing
d) Depends on compiler
Answer:a
#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student *s;
s->c = "hello";
printf("%s", s->c);
}
a) hello
b) Segmentation fault
c) Run time error
d) Nothing
Answer:b
#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student m;
struct student *s = &m;
s->c = "hello";
printf("%s", m.c);
}
Answer:c
#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student m;
struct student *s = &m;
(*s).c = "hello";
printf("%s", m.c);
}
Answer:d
#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student n;
struct student *s = &n;
(*s).c = "hello";
printf("%p\n%p\n", s, &n);
}
a) Different address
b) Run time error
c) Nothing
d) Same address
Answer:d
#include <stdio.h>
struct p
{
int x[2];
};
struct q
{
int *x;
};
int main()
{
struct p p1 = {1, 2};
struct q *ptr1;
ptr1->x = (struct q*)&p1.x;
printf("%d\n", ptr1->x[1]);
}
Answer:b
#include <stdio.h>
struct p
{
int x[2];
};
struct q
{
int *x;
};
int main()
{
struct p p1 = {1, 2};
struct q *ptr1 = (struct q*)&p1;
ptr1->x = (struct q*)&p1.x;
printf("%d\n", ptr1->x[0]);
}
a) Compile time error
b) Undefined behaviour
c) Segmentation fault/code crash
d) 1
Answer:b
#include <stdio.h>
struct p
{
int x;
int y;
};
int main()
{
struct p p1[] = {1, 2, 3, 4, 5, 6};
struct p *ptr1 = p1;
printf("%d %d\n", ptr1->x, (ptr1 + 2)->x);
}
a) 1 5
b) 1 3
c) Compile time error
d) 1 4
Answer:a
#include <stdio.h>
struct p
{
int x;
char y;
};
int main(){
struct p p1[] = {1, 92, 3, 94, 5, 96};
struct p *ptr1 = p1;
int x = (sizeof(p1) / sizeof(struct p));
printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x);
}
Answer:d
91. What is the output of this C code (considering sizeof char is 1 and pointer is 4)?
#include <stdio.h>
int main()
{
char *a[2] = {"hello", "hi"};
printf("%d", sizeof(a));
return 0;
}
a) 9
b) 4
c) 8
d) 10
Answer:c
#include <stdio.h>
int main()
{
char a[2][6] = {"hello", "hi"};
printf("%d", sizeof(a));
return 0;
}
a) 9
b) 12
c) 8
d) 10
Answer:b
#include <stdio.h>
int main()
{
char a[2][6] = {"hello", "hi"};
printf("%s", *a + 1);
return 0;
}
a) hello
b) hi
c) ello
d) ello hi
Answer:c
94. What is the output of this C code?
#include <stdio.h>
int main()
{
char *a[2] = {"hello", "hi"};
printf("%s", *(a + 1));
return 0;
}
a) hello
b) ello
c) hi
d) ello hi
Answer:c
Answer:d
Answer:c
Answer:c
Answer:d
Answer:b
Answer:a
Answer:d
Answer:c
103. What would be the output if we try to execute following segment of code (assuming the following
input “cool brother in city”)?
printf(“%s\n”, argv[argc]);
a) (null)
b) City
c) In
D. Segmentation Fault
Answer:a
Answer:b
Answer:a
((MARKS)) (1/2/3...) 1
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
((OPTION_A)) 2,1,15
((OPTION_B)) 1,2,5
((OPTION_C)) 3,2,15
((OPTION_D)) 2,3,20
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION)) Step 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an
(OPTIONAL) integer array with a size of 5 and it is initialized to
a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .
Step 2: int i, j, m; The variable i,j,m are declared as an integer type.
Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2
Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.
Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is
incremented by 1(i++ means 2++ so i=3)
Step 6: printf("%d, %d, %d", i, j, m); It prints the value of the
variables i, j, m
Hence the output of the program is 3, 2, 15
((MARKS)) (1/2/3...) 1
((QUESTION)) In C, if you pass an array as an argument to a function, what actually
passed?
((OPTION_A)) Value of elements in array
((OPTION_B)) First element of the array
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION)) The statement 'C' is correct. When we pass an array as a funtion argument,
(OPTIONAL) the base address of the array will be passed.
((MARKS)) (1/2/3...) 1
Which of the following statements are correct about 6 used in the
((QUESTION))
program?
int num[6];
num[6]=21;
((OPTION_A)) In the first statement 6 specifies a particular element, whereas in
the second statement it specifies a type.
((OPTION_B)) In the first statement 6 specifies a array size, whereas in the second
statement it specifies a particular element of array.
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION)) The statement 'B' is correct, because int num[6]; specifies the size of
(OPTIONAL) array and num[6]=21; designates the particular element(7thelement) of
the array.
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) 1
((OPTION_B)) 1,4
((OPTION_C)) 2,3
((OPTION_D)) 2,4
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION)) 1. The array int num[26]; can store 26 elements. This statement is true.
(OPTIONAL) 2. The expression num[1] designates the very first element in the array.
This statement is false, because it designates the second element of the
array.
3. It is necessary to initialize the array at the time of declaration. This
statement is false.
4. The declaration num[SIZE] is allowed if SIZE is a macro. This
statement is true, because the MACRO just replaces the symbol SIZE
with given value.
Hence the statements '1' and '4' are correct statements.
((MARKS)) (1/2/3...) 1
((OPTION_C)) Range
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) Which of the following function is used to find the first occurrence of a
given string in another string?
((OPTION_A)) strchr()
((OPTION_B)) strrchr()
((OPTION_C)) strstr()
((OPTION_D)) strnset()
((CORRECT_CHOICE)) C
(A/B/C/D)
((MARKS)) (1/2/3...) 1
((OPTION_A)) BIG-O
((OPTION_B)) Omega
((OPTION_C)) Phi
((OPTION_D)) Theta
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) 5 times
((OPTION_C)) Infinite
((OPTION_D)) No execution
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_D)) None
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) Array
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) Facebook
((OPTION_B)) Searching
((OPTION_C)) Sorting
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) Queue
((OPTION_B)) Stack
((OPTION_C)) Array
((OPTION_D)) List
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) In a linked list with n nodes, the time taken to insert an
element after an element pointed by some pointer is……..
((OPTION_A)) O (1)
((OPTION_B)) O(log n)
((OPTION_C)) O(n)
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) +
((OPTION_B)) /
((OPTION_C)) %
((OPTION_D)) *
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) Allloc()
((OPTION_B)) Malloc()
((OPTION_C)) Calloc()
((OPTION_D)) Free()
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) Which of the following case does not exist in complexity theory
((OPTION_A)) Best case
((OPTION_B)) Worst case
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_D)) Item is the last element in the array or is not there at all
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION)) .
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) O(n)
((OPTION_B)) O(log n)
((OPTION_C)) O(n2)
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) The input to a merge sort is 6,5,4,3,2,1 and the same input is
applied to quick sort then which is the best algorithm in this case
((OPTION_C)) Both have same time complexity in this case as they have same
running time
((OPTION_D)) Cannot be decided
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) If there exists two functions f(n) and g(n). The constant c>0 and
there exists an integer constant n0>=1. If f(n)<=c*g(n) for every
integer n>= n0 then we say that____
((OPTION_A)) f(n)=O(g(n))
((MARKS)) (1/2/3...) 1
((OPTION_A)) Big oh
((CORRECT_CHOICE)) A
(A/B/C/D)
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION)) All these operations are computed by single line expression evaluation
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION)) Within two for loops(nested), all these operations are performed.
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) O(1)
((OPTION_B)) O(n)
((OPTION_C)) O(log n)
((OPTION_D)) O(n2)
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((OPTION_A)) O(n)
((OPTION_B)) O(log n)
((OPTION_D)) O(n2)
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION)) The list is divided at the mid and then the element is searched in either
(OPTIONAL) left half or right half.
((MARKS)) (1/2/3...) 1
((OPTION_A)) O(n)
((OPTION_B)) O(log n)
((OPTION_D)) O(n2)
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION)) T(n)=T(n-1)+c2
(OPTIONAL) =T(n-2)+2c2
=T(n-3)+3c2
=T(n-k)+kc2
If k=n then T(n)=c1+nc2 Hence, T(n)=O(n)
((MARKS)) (1/2/3...) 1
((OPTION_A)) O(n)
((OPTION_B)) O(log n)
((OPTION_D)) O(n2)
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_B)) Backtracking
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) The recurrence relation for factorial function is of the form _______
((OPTION_A)) T(n)=T(n-1)+c
((OPTION_B)) T(n)=T(n-1)+T(n-2)+c
((OPTION_C)) T(n/2)+c
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION)) The factorial function is as follows-
(OPTIONAL) fact(n)
{
if n=1
return 1
else
return n * fact(n-1)
}
((MARKS)) (1/2/3...) 1
((OPTION_A)) T(n)=T(n-1)+c
((OPTION_B)) T(n)=T(n-1)+T(n-2)+c
((OPTION_C)) T(n/2)+c
((CORRECT_CHOICE)) B
(A/B/C/D)
((MARKS)) (1/2/3...) 1
((OPTION_A)) m + mn + mn
((OPTION_B)) m + n + mn
((OPTION_C)) m + n2 + mn
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) T(n)=O(n4)
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) ½(n2+n)
((OPTION_B)) ½(n2+3n)
((OPTION_C)) n2
((OPTION_D)) (n+1)2
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) There are four algorithms for solving a problem. Their time
complexities
are O(n), O(n2), O(log n) and O(n log n). Which is the best
algorithm?
((OPTION_A)) O(n)
((OPTION_B)) O(n2)
((OPTION_C)) O(log n)
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) 3
((OPTION_B)) 2
((OPTION_C)) 1
((OPTION_D)) B
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) 1, -1
((OPTION_B)) -1, -1
((OPTION_C)) 1, 1
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_B)) Z2+3Z-2=0
((OPTION_C)) Z2+3Z+2=0
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) ar=c1(-2)r
((OPTION_B)) ar=c2(2)r
((OPTION_C)) ar=c1(1)r
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) Consider the recurrence relation, an=an-1+2an-2 with a9=3 and a10=5.
Find a7.
((OPTION_A)) 1
((OPTION_B)) 3
((OPTION_C)) 5
((OPTION_D)) None
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) Charactristic polynomial of the recurrence relation a r+2-ar-2=0 is
______.
((OPTION_A)) Z-1=0
((OPTION_B)) Z2-1=0
((OPTION_C)) (Z-1)2=0
((OPTION_D)) None
((CORRECT_CHOICE)) D
(A/B/C/D)
((MARKS)) (1/2/3...) 1
((OPTION_A)) ab+cd-*
((OPTION_B)) ab+cd*-
((OPTION_C)) abcd+*-
((OPTION_D)) ab-cd+*
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) What does the following function check for? (all necessary headers to
be included and function is called from main)
#define MAX 10
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION)) Answer: c
(OPTIONAL) Explanation: An empty stack is represented with the top-of-the-
stack(‘top’ in this case) to be equal to -1.
MCQs
Suppose we are sorting an array of eight integers using a some quadratic sorting algorithm. After
four iterations of the algorithm’s main loop, the array elements are ordered as shown here:2 4 5 7
8136*
Insertion sort
Selection sort
either of a and b
none of the above
A sort which compares adjacent elements in a list and switches where necessary is *
insertion sort
heap sort
quick sort
bubble sort
The correct order of the efficiency of the following sorting algorithms according to their overall
running time comparision is *
Insertion>selection>bubble
Insertion>bubble>selection
Selection>bubble>insertion
bubble>selection>insertion
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 *
insertion sort
selection sort
heap sort
quick sort
The number of swappings needed to sort the numbers 8, 22, 7, 9, 31, 19, 5, 13 in ascending order,
using bubble sort is *
10
9
13
14
The way a card game player arranges his cards as he picks them one by one can be compared
to *
Quick sort
Merge sort
Insertion sort
Bubble sort
Which among the following is the best when the list is already sorted *
Insertion sort
Bubble sort
Merge sort
Selection sort
As part of the maintenance work, you are entrusted with the work of rearranging the library books
in a shelf in proper order, at the end of each day. The ideal choice will be *
Bubble sort
Insertion sort
Selection sort
Merge sort
MCQs
a) 3 and 5
b) 5 and 3
c) 2 and 4
d) 4 and 2
Answer: a
Explanation: Array indexing starts from 0.
a) 4
b) 5
c) ArrayIndexOutOfBoundsException
d) InavlidInputException
Answer: c
Explanation: Trying to access an element beyond the limits of an array gives
ArrayIndexOutOfBoundsException.
Queues:
1. A linear list of elements in which deletion can be done from one end (front) and insertion can take place
only at the other end (rear) is known as a ?
a) Queue
b) Stack
c) Tree
d) Linked list
Answer: a
Explanation: Self Explanatory.
3. A queue is a ?
a) FIFO (First In First Out) list
b) LIFO (Last In First Out) list
c) Ordered array
d) Linear tree
View Answer
Answer: a
Explanation: Self Explanatory.
4. In Breadth First Search of Graph, which of the following data structure is used?
a) Stack
b) Queue
c) Linked list
d) None of the mentioned
View Answer
Answer: b
Explanation: Self Explanatory.
5. If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a time, in what order
will they be removed?
a) ABCD
b) DCBA
c) DCAB
d) ABCD
Answer: a
Explanation: Queue follows FIFO approach.
6. A data structure in which elements can be inserted or deleted at/from both the ends but not in the middle
is?
a) Queue
b) Circular queue
c) Dequeue
d) Priority queue
Answer: c
Explanation: Self Explanatory.
7. A normal queue, if implemented using an array of size MAX_SIZE, gets full when
a) Rear = MAX_SIZE – 1
b) Front = (rear + 1)mod MAX_SIZE
c) Front = rear + 1
d) Rear = front
Answer: a
Explanation: Condition for size of queue.
10. In linked list implementation of queue, if only front pointer is maintained, which of the following operation
take worst case linear time?
a) Insertion
b) Deletion
c) To empty a queue
d) Both a and c
Answer: d
Explanation: Since front pointer is used for deletion, so worst time for the other two cases.
11. In linked list implementation of a queue, where does a new element be inserted?
a) At the head of link list
b) At the centre position in the link list
c) At the tail of the link list
d) None of the mentioned
Answer: c
Explanation: Since queue follows FIFO so new element inserted at last.
12. In linked list implementation of a queue, front and rear pointers are tracked. Which of these pointers will
change during an insertion into a NONEMPTY queue?
a) Only front pointer
b) Only rear pointer
c) Both front and rear pointer
d) None of the mentioned
Answer: b
Explanation: Since queue follows FIFO so new element inserted at last.
((MARKS)) (1/2/3...) 1
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
((OPTION_A)) 2,1,15
((OPTION_B)) 1,2,5
((OPTION_C)) 3,2,15
((OPTION_D)) 2,3,20
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION)) Step 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an
(OPTIONAL) integer array with a size of 5 and it is initialized to
a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .
Step 2: int i, j, m; The variable i,j,m are declared as an integer type.
Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2
Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.
Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is
incremented by 1(i++ means 2++ so i=3)
Step 6: printf("%d, %d, %d", i, j, m); It prints the value of the
variables i, j, m
Hence the output of the program is 3, 2, 15
((MARKS)) (1/2/3...) 1
((QUESTION)) In C, if you pass an array as an argument to a function, what actually
passed?
((OPTION_A)) Value of elements in array
((OPTION_B)) First element of the array
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION)) The statement 'C' is correct. When we pass an array as a funtion argument,
(OPTIONAL) the base address of the array will be passed.
((MARKS)) (1/2/3...) 1
((QUESTION)) Which of the following statements are correct about 6 used in the
program?
int num[6];
num[6]=21;
((OPTION_A)) In the first statement 6 specifies a particular element, whereas in
the second statement it specifies a type.
((OPTION_B)) In the first statement 6 specifies a array size, whereas in the second
statement it specifies a particular element of array.
((EXPLANATION)) The statement 'B' is correct, because int num[6]; specifies the size of
(OPTIONAL) array and num[6]=21; designates the particular element(7thelement) of
the array.
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) 1
((OPTION_B)) 1,4
((OPTION_C)) 2,3
((OPTION_D)) 2,4
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION)) 1. The array int num[26]; can store 26 elements. This statement is true.
(OPTIONAL) 2. The expression num[1] designates the very first element in the array.
This statement is false, because it designates the second element of the
array.
3. It is necessary to initialize the array at the time of declaration. This
statement is false.
4. The declaration num[SIZE] is allowed if SIZE is a macro. This
statement is true, because the MACRO just replaces the symbol SIZE
with given value.
Hence the statements '1' and '4' are correct statements.
((MARKS)) (1/2/3...) 1
((QUESTION)) If the two strings are identical, then strcmp() function returns
((OPTION_A)) -1
((OPTION_B)) 1
((OPTION_C)) 0
((OPTION_D)) Yes
((CORRECT_CHOICE)) C
(A/B/C/D)
((MARKS)) (1/2/3...) 1
((QUESTION)) Which of the following function is used to find the first occurrence of a
given string in another string?
((OPTION_A)) strchr()
((OPTION_B)) strrchr()
((OPTION_C)) strstr()
((OPTION_D)) strnset()
((CORRECT_CHOICE)) C
(A/B/C/D)
((MARKS)) (1/2/3...) 1
((QUESTION)) The library function used to find the last occurrence of a character
string is
((OPTION_A)) strnstr()
((OPTION_B)) laststr()
((OPTION_C)) strrchr()
((OPTION_D)) strstr()
((CORRECT_CHOICE)) C
(A/B/C/D)
int main(void)
{
char text[] = "I learn through IndiaBIX.com";
char *ptr, c = 'i';
((MARKS)) (1/2/3...) 1
((OPTION_A)) printf("\n");
((OPTION_C)) printf('\n');
((OPTION_D)) printf("\\n");
((CORRECT_CHOICE)) D
(A/B/C/D)
((MARKS)) (1/2/3...) 1
((OPTION_A)) Arrays
((OPTION_B)) Structure
((OPTION_D)) File
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) In arrays ____ and _____ are costly but ____ is easy operation
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) 122
((OPTION_B)) 211
((OPTION_C)) 000
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) 0
((OPTION_B)) 1
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) While passing the array as actual argument, the function call must
array name_____
((OPTION_A)) alone
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) Code 1
((OPTION_B)) Code 2
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) Consider an integer array int arr[4][5]. If base address is 1020, find
s of element arr[3][4] with row major representation. Size of int is 2 bytes.
((OPTION_A)) 1020
((OPTION_B)) 1038
((OPTION_C)) 1039
((OPTION_D)) 1058
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
be at____
((OPTION_A)) Val[0][3]
((OPTION_B)) Val[0][4]
((OPTION_C)) Val[1][1]
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_B)) 2300
((OPTION_C)) 2030
((OPTION_D)) 2003
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) printf
((OPTION_B)) scanf
((OPTION_C)) put
((OPTION_D)) gets
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) a
((OPTION_B)) A
((OPTION_C)) c
((OPTION_D)) 65
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) stack
((OPTION_B)) Queues
((OPTION_C)) Arrays
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) 3
((OPTION_B)) 2
((OPTION_C)) 1
((OPTION_D)) 0
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) Which of the following case does not exist in complexity theory
((OPTION_A)) Best case
((OPTION_B)) Worst case
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_D)) Item is the last element in the array or is not there at all
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION)) .
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) O(n)
((OPTION_B)) O(log n)
((OPTION_C)) O(n2)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) The input to a merge sort is 6,5,4,3,2,1 and the same input is
applied to quick sort then which is the best algorithm in this case
((OPTION_C)) Both have same time complexity in this case as they have same
running time
((OPTION_D)) Cannot be decided
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) If there exists two functions f(n) and g(n). The constant c>0 and
there exists an integer constant n0>=1. If f(n)<=c*g(n) for every
integer n>= n0 then we say that____
((OPTION_A)) f(n)=O(g(n))
((MARKS)) (1/2/3...) 1
((OPTION_A)) Big oh
((CORRECT_CHOICE)) A
(A/B/C/D)
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION)) All these operations are computed by single line expression evaluation
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION)) Within two for loops(nested), all these operations are performed.
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_B)) O(n)
((OPTION_C)) O(log n)
((OPTION_D)) O(n2)
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) O(n)
((OPTION_B)) O(log n)
((OPTION_D)) O(n2)
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION)) The list is divided at the mid and then the element is searched in either
(OPTIONAL) left half or right half.
((MARKS)) (1/2/3...) 1
((OPTION_A)) O(n)
((OPTION_B)) O(log n)
((OPTION_D)) O(n2)
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION)) T(n)=T(n-1)+c2
(OPTIONAL) =T(n-2)+2c2
=T(n-3)+3c2
=T(n-k)+kc2
If k=n then T(n)=c1+nc2 Hence, T(n)=O(n)
((MARKS)) (1/2/3...) 1
((OPTION_A)) O(n)
((OPTION_B)) O(log n)
((OPTION_D)) O(n2)
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_B)) Backtracking
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) The recurrence relation for factorial function is of the form _______
((OPTION_A)) T(n)=T(n-1)+c
((OPTION_B)) T(n)=T(n-1)+T(n-2)+c
((OPTION_C)) T(n/2)+c
((MARKS)) (1/2/3...) 1
((OPTION_A)) T(n)=T(n-1)+c
((OPTION_B)) T(n)=T(n-1)+T(n-2)+c
((OPTION_C)) T(n/2)+c
((CORRECT_CHOICE)) B
(A/B/C/D)
((MARKS)) (1/2/3...) 1
((OPTION_A)) m + mn + mn
((OPTION_B)) m + n + mn
((OPTION_C)) m + n2 + mn
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) T(n)=O(n4)
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) ½(n2+n)
((OPTION_B)) ½(n2+3n)
((OPTION_C)) n2
((OPTION_D)) (n+1)2
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) There are four algorithms for solving a problem. Their time
complexities
are O(n), O(n2), O(log n) and O(n log n). Which is the best
algorithm?
((OPTION_A)) O(n)
((OPTION_B)) O(n2)
((OPTION_C)) O(log n)
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) 3
((OPTION_B)) 2
((OPTION_C)) 1
((OPTION_D)) B
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) 1, -1
((OPTION_B)) -1, -1
((OPTION_C)) 1, 1
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) Z2-3Z-2=0
((OPTION_B)) Z2+3Z-2=0
((OPTION_C)) Z2+3Z+2=0
((CORRECT_CHOICE)) C
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) ar=c1(-2)r
((OPTION_B)) ar=c2(2)r
((OPTION_C)) ar=c1(1)r
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) Consider the recurrence relation, an=an-1+2an-2 with a9=3 and a10=5.
Find a7.
((OPTION_A)) 1
((OPTION_B)) 3
((OPTION_C)) 5
((OPTION_D)) None
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) Z-1=0
((OPTION_B)) Z2-1=0
((OPTION_C)) (Z-1)2=0
((OPTION_D)) None
((CORRECT_CHOICE)) D
(A/B/C/D)
((MARKS)) (1/2/3...) 1
((OPTION_A)) ar+2-ar-2=0
((OPTION_B)) ar=ar-1+ar-2
((OPTION_C)) ar-2ar-1=-ar-2
((OPTION_D)) ar+3+6ar+2.ar+1-4ar=0
((CORRECT_CHOICE)) D
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) If 4 and -1 are the characteristic roots of the recurrence relation then
its homogeneous solution becomes _______
((OPTION_A)) ar=c1(-1)r+c2(4)r
((OPTION_B)) ar=c0(-1)r+c2
((OPTION_C)) ar=(c1+c2.r)(-1)r
((OPTION_D)) None
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((OPTION_A)) Linear
((OPTION_B)) Homogeneous
((OPTION_C)) Quadratic
((OPTION_D)) None
((CORRECT_CHOICE)) A
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)
((MARKS)) (1/2/3...) 1
((QUESTION)) The generating function for the sequence 1, a, a2, a3, ….. is ______
((OPTION_A)) 1/(1-z)
((OPTION_B)) 1/(1-az)
((OPTION_C)) 1/(1+az)
((OPTION_D)) None
((CORRECT_CHOICE)) B
(A/B/C/D)
((EXPLANATION))
(OPTIONAL)