MCQ1 mark
A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT ( refers to the number of items in the queue)?
Single correct
Answer key coming soon
GATE CSE previous year questions · Programming & Data Structures
Single correct
Answer key coming soon
void f(int, short);
void main()
{
int i = 100;
short s = 12;
short *p = &s;
__________ ; // call to f()
}
Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?Single correct
Answer key coming soon
#include<stdio.h>
void mystery(int *ptra, int *ptrb) {
int *temp;
temp = ptrb;
ptrb = ptra;
ptra = temp;
}
int main() {
int a=2016, b=0, c=4, d=42;
mystery(&a, &b);
if (a < c)
mystery(&c, &a);
mystery(&a, &d);
printf("%d\n", a);
}
The output of the program is ________.Numerical answer
Answer key coming soon
int max(int *p, int n) {
int a=0, b=n-1;
while (__________) {
if (p[a] <= p[b]) { a = a+1; }
else { b = b-1; }
}
return p[a];
}
The missing loop condition isSingle correct
Answer key coming soon
void count(int n){
static int d=1;
printf("%d ", n);
printf("%d ", d);
d++;
if(n>1) count(n-1);
printf("%d ", d);
}
void main(){
count(3);
}Single correct
Answer key coming soon
Single correct
Answer key coming soon
while Q is not Empty do
if S is Empty OR Top(S) ≤ Head(Q) then
x := Dequeue(Q);
Push(S,x);
else
x := Pop(S);
Enqueue(Q,x);
end
end
The maximum possible number of iterations of the while loop in the algorithm is ________.Numerical answer
Answer key coming soon
Numerical answer
Answer key coming soon
void f(int* p, int m){
m = m + 5;
*p = *p + m;
return;
}
void main(){
int i=5, j=10;
f(&i, j);
printf("%d", i+j);
}Numerical answer
Answer key coming soon
Single correct
Answer key coming soon
Numerical answer
Answer key coming soon
int exp(int X, int Y) {
int res = 1, a = X, b = Y;
while ( b != 0 ){
if ( b%2 == 0) { a = a*a; b = b/2; }
else { res = res*a; b = b-1; }
}
return res;
}
Which one of the following conditions is TRUE before every iteration of the loop?Single correct
Answer key coming soon
Single correct
Answer key coming soon
int f(int *p, int n)
{
if (n <= 1) return 0;
else return max(f(p+1,n-1),p[0]-p[1]);
}
int main()
{
int a[] = {3,5,2,6,4};
printf("%d", f(a,5));
}
*Note*: max(x,y) returns the maximum of x and y.
The value printed by this program is ________.Numerical answer
Answer key coming soon
Numerical answer
Answer key coming soon