1. What will be the output of the following C code?
#include <stdio.h>
int main()
{
int *p = (int *)2;
int *q = (int *)3;
printf(“%d”, p + q);
}
a) 2
b) 3
c) 5
d) Compile time error
Answer : D
2. What will be the output of the program ?
#include<stdio.h>
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;
}
A.2, 1, 15
B.1, 2, 5
C.3, 2, 15
D.2, 3, 20
Answer : C
3. The number of swappings needed to sort the numbers 8, 22, 7, 9, 31, 5, 13 in ascending order, using bubble sort is
(A) 11
(B) 12
(C) 13
(D) 10
Answer : d
4. Consider the following three C functions :
[PI] int * g (void)
{
int x = 10;
return (&x);
}
[P2] int * g (void)
{
int * px;
*px = 10;
return px;
}
[P3] int *g (void)
{
int *px;
px = (int *) malloc (sizeof(int));
*px = 10;
return px;
}
Which of the above three functions are likely to cause problems with pointers?
(a) Only P3
(b) Only P1 and P3
(c) Only P1 and P2
(d) P1, P2 and P3
Answer : C
5. 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);
}
(a) 10
(b) 4
(c) 6
(d) 7
Answer : A
C MCQ Set-16 Explanation
6. Consider the following C declaration
struct
{
short s [5]
union
{
float y;
long z;
}u;
} t;
Assume that objects of the type short, float and long occupy 2 bytes, 4 bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment
considerations, is
(a) 22 bytes
(b) 14 bytes
(c) 18 bytes
(d) 10 bytes
Answer : C
7. In the C language:
a) At most one activation record exists between the current activation record and the activation record for the main
b) The number of activation records between the current activation record and the activation record for the main depends on the actual function calling sequence.
c) The visibility of global variables depends on the actual function calling sequence.
d) Recursion requires the activation record for the recursive function to be saved on a different stack before the recursive function can be called.
Answer : B
8. Consider the C program shown below.
#include<stdio.h>
#define print (x) printf (“%d”,x)
int x;
void Q(int z)
{
z += x;
print(z);
}
void P(int *y)
{
int x = *y+2;
Q(x);
*y = x-1;
print(x);
}
main(void)
{
x=5;
P(&x);
print(x);
getchar();
}
The output of this program is:
a) 12 7 6
b) 22 12 11
c) 14 6 6
d) 766
Answer : A
C MCQ Set-16 Explanation
9. Consider the following declaration of a ‘two-dimensional array in C:
char a[100][100];
Assuming that the main memory is byte-addressable and that the array is stored starting from memory address 0,
and size of char is 1 byte. In row major implementation, the address of a[40][50] is :
a) 4040
b) 4050
c) 5040
d) 5050
Answer : B
10. The most appropriate matching for the following pairs:
X: m=malloc(5); m= NULL; 1: using dangling pointers
Y: free(ptr); ptr->value=5; 2: using uninitialized pointers
Z: char *p; *p = ’a’; 3. lost memory is:
(a) X—1 Y—3 Z-2
(b) X—2 Y—1 Z-3
(C) X—3 Y—2 Z-1
(d) X—3 Y—1 Z-2
Answer : D