Question 1
The following C declarations
struct node
{
int i;
float j;
};
struct node *s[10] ;
define s to be
An array, each element of which is a pointer to a structure of type node
A structure of 2 fields, each field being a pointer to an array of 10 elements
A structure of 3 fields: an integer, a float, and an array of 10 elements
An array, each element of which is a structure of type node.
Question 2
The value of j at the end of the execution of the following C program.
int incr(int i)
{
static int count = 0;
count = count + i;
return (count);
}
main()
{
int i,j;
for (i = 0; i <=4; i++)
j = incr(i);
}
10
4
6
7
Question 3
Suppose n and p are unsigned int variables in a C program. We wish to set p to nC3. If n is large, which of the following statements is most likely to set p correctly?
p = n * (n-1) * (n-2) / 6;
p = n * (n-1) / 2 * (n-2) / 3;
p = n * (n-1) / 3 * (n-2) / 2;
p = n * (n-1) * (n-2) / 6.0;
Question 4
Consider the following C program:
# include <stdio.h>
int main( )
{
int i, j, k = 0;
j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
k -= --j;
for (i = 0; i < 5; i++)
{
switch(i + k)
{
case 1:
case 2: printf("\n%d", i + k);
case 3: printf("\n%d", i + k);
default: printf("\n%d", i + k);
}
}
return 0;
}
The number of times printf statement is executed is __________.
8
9
10
11
Question 5
Consider the following C function:
int f(int n) {
static int i = 1;
if (n >= 5)
return n;
n = n + i;
i++;
return f(n);
}
int f(int n)
{
static int i = 1;
if (n >= 5)
return n;
n = n+i;
i++;
return f(n);
}
public class Main {
static int i = 1;
public static int f(int n) {
if (n >= 5)
return n;
n = n + i;
i++;
return f(n);
}
}
def f(n):
global i
if 'i' not in globals():
i = 1
if n >= 5:
return n
n = n + i
i += 1
return f(n)
let i = 1;
function f(n) {
if (n >= 5)
return n;
n = n + i;
i++;
return f(n);
}
The value returned by f(1) is
5
6
7
8
Question 6
The output of executing the following C program is ________.
# 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) ;
}
23
24
26
27
Question 7
Consider the following C program:
#include<stdio.h>
int r(){
int static num=7;
return num--;
}
int main() {
for(r();r();r()) {
printf("%d ",r());
};
return 0;
}
Which one of the following values will be displayed on execution of the programs?
41
52
63
630
There are 7 questions to complete.