MCQ1 mark
Let be a binary search tree with 15 nodes. The minimum and maximum possible heights of are:
*Note: The height of a tree with a single node is 0.*
Single correct
Answer key coming soon
GATE CSE previous year questions · Programming & Data Structures
Single correct
Answer key coming soon
typedef struct node {
int data;
node* next;
} node;
void join(node* m, node* n){
node* p = n;
while(p->next != NULL) {
p = p->next;
}
p->next = m;
}
Assuming that m and n point to valid NULL-terminated linked lists, invocation of join willSingle correct
Answer key coming soon
#include <stdio.h>
int *assignval(int *x, int val) {
*x = val;
return x;
}
void main () {
int *x = malloc(sizeof(int));
if(NULL == x) return;
x = assignval(x,0);
if(x) {
x = (int *)malloc(sizeof(int));
if(NULL == x) return;
x = assignval(x,10);
}
printf("%d\n", *x);
free(x);
}
The code suffers from which one of the following problems:Single correct
Answer key coming soon
void fun1(int n) { void fun2(int n) {
if(n == 0) return; if(n == 0) return;
printf("%d", n); printf("%d", n);
fun2(n - 2); fun1(++n);
printf("%d", n); printf("%d", n);
} }
The output printed when fun1(5) is called isSingle correct
Answer key coming soon
int foo(int val) {
int x = 0;
while(val > 0) {
x = x + foo(val--);
}
return val;
}
int bar(int val) {
int x = 0;
while(val > 0) {
x = x + bar(val-1);
}
return val;
}
Invocations of foo(3) and bar(3) will result in:Single correct
Answer key coming soon
#include <stdio.h>
#include <string.h>
void printlength(char *s, char *t) {
unsigned int c = 0;
int len = ((strlen(s) - strlen(t)) > c) ? strlen(s): strlen(t);
printf("%d\n", len);
}
void main() {
char *x = "abc";
char *y = "defgh";
printlength(x,y);
}
Recall that strlen is defined in string.h as returning a value of type size_t, which is an unsigned int. The output of the program is ________.Numerical answer
Answer key coming soon
#include <stdio.h>
int total(int v) {
static int count = 0;
while(v) {
count += v&1;
v >>= 1;
}
return count;
}
void main() {
static int x = 0;
int i = 5;
for(; i > 0; i--) {
x = x + total(i);
}
printf("%d\n", x);
}Numerical answer
Answer key coming soon
(P) static char var; (i) Sequence of memory locations to store addresses
(Q) m = malloc(10); (ii) A variable located in data section of memory
m = NULL;
(R) char *ptr[10]; (iii) Request to allocate a CPU register to store data
(S) register int var1; (iv) A lost memory which cannot be freedSingle correct
Answer key coming soon
Single correct
Answer key coming soon
void printxy(int x, int y) {
int *ptr;
x = 0;
ptr = &x;
y = *ptr;
*ptr = 1;
printf("%d,%d",x,y);
}
The output of invoking printxy(1,1) isSingle correct
Answer key coming soon
Single correct
Answer key coming soon
while (r >= y) {
r = r - y;
q = q + 1;
}
Which of the following conditions on the variables x, y, q and r before the execution of the fragment will ensure that the loop terminates in a state satisfying the condition x == (y*q + r)?Single correct
Answer key coming soon
int main() {
int array[] = {3, 5, 1, 4, 6, 2};
int done = 0;
int i;
while (done == 0) {
done = 1;
for (i=0; i<=4; i++) {
if (array[i] < array[i+1]) {
swap(&array[i], &array[i+1]);
done = 0;
}
}
for (i=5; i>=1; i--) {
if (array[i] > array[i-1]) {
swap(&array[i], &array[i-1]);
done = 0;
}
}
}
printf("%d",array[3]);
}
The output of the program is ________.Numerical answer
Answer key coming soon
#include<stdio.h>
int main() {
int m = 10;
int n, n1;
n = ++m;
n1 = m++;
n--;
--n1;
n -= n1;
printf("%d", n);
return 0;
}
The output of the program is ________.Numerical answer
Answer key coming soon
#include<stdio.h>
#include<string.h>
int main() {
char* c = "GATECSIT2017";
char* p = c;
printf("%d", (int)strlen(c+2[p]-6[p]-1));
return 0;
}
The output of the program is ________.Numerical answer
Answer key coming soon