Q10
Consider the function func shown below:
int func(int num) {
int count = 0;
while (num) {
count++;
num>>= 1;
}
return (count);
}The value returned by func(435) is __________.
Show answer without attempting
Answer: 9
GATE CS · 14 questions
14 Programming and Data Structures questions from GATE CS papers (2014), each with the official answer key. Answer any question right here and it is marked straight away, or practise them one at a time.
int func(int num) {
int count = 0;
while (num) {
count++;
num>>= 1;
}
return (count);
}Answer: 9
Answer: B
Answer: A

Answer: 6
double f(double x){
if( abs(x*x - 3) < 0.01) return x;
else return f(x/2 + 1.5/x);
}Answer: 1.72 to 1.74
Answer: C
int f(int j)
{
static int i = 50;
int k;
if (i == j)
{
printf("something");
k = f(i);
return 0;
}
else return 0;
}Answer: D
C = 100;
for i = 1 to n do
for j = 1 to n do
{
Temp = A[i][j] + C;
A[i][j] = A[j][i];
A[j][i] = Temp - C;
}
for i = 1 to n do
for j = 1 to n do
output (A[i][j]);Answer: A

Answer: A
Answer: 110
typedef struct treeNode* treeptr;
struct treeNode
{
treeptr leftMostChild, rightSibling;
};
int DoSomething (treeptr tree)
{
int value=0;
if (tree != NULL) {
if (tree->leftMostChild == NULL)
value = 1;
else
value = DoSomething(tree->leftMostChild);
value = value + DoSomething(tree->rightSibling);
}
return(value);
}Answer: D
int ProcessArray(int *listA, int x, int n)
{
int i, j, k;
i = 0;
j = n-1;
do {
k = (i+j)/2;
if (x <= listA[k])
j = k-1;
if (listA[k] <= x)
i = k+1;
}while (i <= j);
if (listA[k] == x)
return(k);
else
return -1;
}Answer: B
#include <stdio.h>
main()
{
int i;
int *pi = &i;
scanf("%d",pi);
printf("%d\n", i+5);
}Answer: D
Answer: 1
0/140 correct0 marks