NEW
Font size
WorksheetsUnit-2 Test-2
Total questions: 15
Worksheet time: 1hrs 21mins
What will be the output of the following C code?
int a[2][3] = {1, 2, 3, 4, 5};
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
printf("%d", a[i][j]);
1 2 3 4 5 0
1 2 3 4 5 junk
1 2 3 4 5 5
Run time error
What will be the output of the following C code?
int a[2][3] = {1, 2, 3, , 4, 5};
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
printf("%d", a[i][j]);
1 2 3 junk 4 5
Compile time error
1 2 3 0 4 5
1 2 3 3 4 5
What will be the output of the following C code?
int a[2][3] = {0};
a[0][1] = 3;
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
printf("%d", a[i][j]);
0 3 0 0 0 0
Junk 3 junk junk junk junk
Compile time error
All junk values
Which of the following is not possible statically in C?
Jagged Array
Rectangular Array
Cuboidal Array
Multidimensional Array
What are the applications of a multidimensional array?
Matrix-Multiplication
Minimum Spanning Tree
Finding connectivity between nodes
All of the mentioned
What will be the output of the following C code?
int ary[2][3];
ary[][] = {{1, 2, 3}, {4, 5, 6}};
printf("%d\n", ary[1][0]);
Compile time error
4
1
2
What is the output of this program?
int a[10][20][30]={0};
printf("%ld", &a+1 - &a);
1
2
0
-1
What is the output of the following program? (Assume input is 10)
int a;
printf("%d",scanf("%d",&a));
1
10
0
32647
What will be the output of the following code?
unsigned int a = 5;
if(a > -1)
printf("5 is > -1\n");
5 is > -1
error
nothing will be displayed in output
none of the above
What will be the output of the following code?
#include <stdio.h> int main() {
{ char a = 5; int b = 5; if(a == b) printf("char and int compared equal\n"); }
{ int a = 5; long int b = 5; if(a == b) printf("int and long compared equal\n"); }
{ float a = 5.0; double b = 5.0; if(a == b) printf("float and double compared equal\n"); }
{ float a = 5.2; double b = 5.2; if(a == b) printf("float and double again compared equal\n"); }
{ float a = 5.2; if(a == 5.2) printf("float compared equal with constant\n"); }
{ double a = 5.2; if(a == 5.2) printf("double compared equal with constant\n"); } return 0;}
char and int compared equal
int and long compared equal
float and double compared equal
double compared equal with constant
char and int compared equal
int and long compared equal
float and double compared equal
float compared equal with constant
double compared equal with constant
char and int compared equal
int and long compared equal
float and double compared equal
float and double again compared equal
float compared equal with constant
double compared equal with constant
float and double compared equal
float and double again compared equal
float compared equal with constant
double compared equal with constant
The number of tokens in the following C statement.
printf("i = %d, &i = %x", i, &i);
3
26
10
21
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, the address of a[40][50] is
4040
4050
5040
5050
Which combination of the integer variables x, y and z makes the variable a get the value 4 in the following expression?
a = (x > y)? ((x > z)? x : z): ((y > z)? y : z)
x=3; y=4; z=2
x=3; y=4; z=3
x=6;y=3;z=5
x=5; y=4; z=5
Consider the C program given below. What does it print?
#include <stdio.h>
int main ()
{
int i, j;
int a [8] = {1, 2, 3, 4, 5, 6, 7, 8};
for(i = 0; i < 3; i++) {
a[i] = a[i] + 1;
i++;
}
i--;
for (j = 7; j > 4; j--) {
int i = j/2;
a[i] = a[i] - 1;
}
printf ("%d, %d", i, a[i]);
}
2,3
2,4
3,2
3,3
Consider the following snippet of a C program. Assume that swap(&x, &y) exchanges the contents of x and y.
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]); }
3
4
5
6
