All mock tests are FREE till 31 December — register to save your progress
Paper 2 CS · UNIT 03 · MOCK TEST

Mock 2 – C Programming (Part 2)

Unit 3: Programming Languages and Computer Graphics · 30 questions · about 36 minutes. Press End Mock any time to see your score and the correct answers.

All 10 topic-wise mocks in this unit
0 / 30 answered 00:00
Q1. Given
int arr[3][4][2] = {{{2,4},{7,8},{3,4},{5,6}}, {{7,6},{3,4},{5,3},{2,3}}, {{8,9},{7,2},{3,4},{5,1}}};
Which one of the following can be used to refer to the element 1 in the above 3-D array?
Q2. Match List I with List II
List IList II
A. 2-D Array InputI. Liquid Crystal Display
B. Transmissive deviceII. Flat-bed scanner
C. Binary imageIII. Camera
D. 1-D Array inputIV. Inkjet printer
Q3. Pointers cannot be used to
Q4. Which statement is false?
Q5. Which of the following UML diagrams has a static view?
Q6. Using the same table T (17 rows × 1024 columns, 32-bit word-addressable entries, 16 page frames of 1024 words each, LRU) and the same column-averaging program as above, now consider T stored in column-major format. How many page faults will be encountered while running the program?
for j = 0 to 1023:
  temp = 0
  for i = 0 to 16:
    temp = temp + T[i][j]
  print(temp / 17.0)
Q7.

What would be the equivalent pointer expression for referring the array element ar[ m ][ n ][0]

Q8.

Only legal pointer operations: →

A. pointer + number pointer →

B. pointer - number number →

C. pointer + pointer pointer →

D. pointer - pointer pointer →

E. pointer - pointer number

Q9.

Which of the following statements about pointers in C are TRUE.

(A) Pointers can be used to access array elements

(B) Pointers can store the address of another pointer

(C) Pointers are automatically deferenced in expression

(D) Pointers cannot be used to access structure members

Q10.
#include<stdio.h>
void f1(char *x, char *y) {
char *t1;
t1 = x;
x = y;
y = t1;
}
void f2(char **x, char **y) {
char *t1;
t1 = *x;
*x = *y;
*y = t1;
}
int main() {
char *a = "ONE", *b = "TWO";
f1(a, b);
printf("%s %s ", a, b);
f2(&a, &b);
printf("%s %s", a, b);
return 0;
}
Q11.
#include<iostream.h>
using namespace std;
void swap(int &x, int &y)
{
int temp=x;
x=y;
y=temp;
}
int main()
{
int a=5, b=10;
swap(a,b);
swap(a,b);
cout<<a<<" "<<b;
return 0;
}

What will be the output of the above code?

Q12.

Arrange the following steps of file handling in C in the correct order :

(A) Close the file

(B) Read from or write to the file

(C) Open the file

(D) Check for error

Q13.
#include<stdio.h>
void main()
{
int arr[ ] = {1, 2, 3, 4, 5};
int *p = arr;
printf("%d", *p++);
printf("%d", *(p+1));
}

Find the output of the above code?

Q14.

Match List-I with List-II :

Figure
Q15.

What is x in the following program? # include < stdioh>

int main ()
{typedef (* (* arrfptr [3])()) [10];
arrfptr x ;
return 0;
}
Q16.

Given int arr[3][4][2] = {{{2,4},{7,8},{3,4},{5,6}}, {{7,6},{3,4},{5,3},{2,3}}, {{8,9},{7,2},{3,4},{5,1}}}; which of the following can be used to refer to the element 1?

Q17.

Match List I with List II

Figure
Q18.

Which statement is false?

Q19.

Consider the following recursive Java function:

public static String F(int N) {
  if (N <= 0) return "-";
  return F(N - 3) + N + F(N - 2) + N;
}

The value of F(5) is:

Q20.

With 1-byte chars, 2-byte shorts, 4-byte ints and 8-byte doubles, each aligned to its size, no field reordering, and padding for alignment, how much space does this array use? struct { short s; char c; short t; char d; double r; int i; } A[10];

Q21.

Consider the Java function: public static float f(long m, long n) { float result = (float)m / (float)n; if (m < 0 || n < 0) return 0.0f; else result -= f(m * 2, n * 3); return result; } Which value best approximates f(1, 3)?

Q22.

What is the output? int i, j, x = 0; for (i = 0; i < 5; ++i) for (j = 0; j < i; ++j) { x += (i + j − 1); break; } printf("%d", x);

Q23.

Which of the following are legal C statements? (a) int *P = &44; (b) int *P = &r; (c) int P = &a; (d) int P = a;

Q24.

On a 32-bit x86 machine: typedef struct { union { unsigned char a; unsigned short b; } U; unsigned char c; } S; S B[10]; S *p = &B[4]; S *q = &B[5]; p->U.b = 0x1234; (S takes 32 bits). If M is q − p and N is (int)&(p->c) − (int)p, then (M, N) is

Q25.

Consider the following recursive Java function f that takes two long arguments and returns a

float value :
public static float f(long m, long n)
{
float result =(float )m/(float )n;
if (m<0||n<0)
return 0.0f ;
else
result +=f(m∗2,n∗3);
return result;
}

Which of the following integers best approximates the value of f(2,3)?

Q26.

What does the following Java function perform? (Assume int occupies four bytes of storage) public static int f(

int a)
{ // Pre-conditions : a>0 and no
overflow/underflow occurs int b=0 ;
for (int i=0; i<32; i++)
{
b=b<<1 ;
b=b | (a & 1);
a=a≫>1;// This is a logical shift
}
return b;
}
Q27.

What is the output of the following Java program?

class simple {
    public static void main(String[] args) {
        simple obj = new simple();
        obj.start();
    }
    void start() {
        long[] P = {3, 4, 5};
        long[] Q = method(P);
        System.out.print(P[0] + P[1] + P[2] + ":");
        System.out.print(Q[0] + Q[1] + Q[2]);
    }
    long[] method(long[] R) {
        R[1] = 7;
        return R;
    }
} // end of class
Q28.

What is the output of the following C program? (Assume little-endian representation, with the least significant byte at the lowest address, and a two-byte short int.)

#include <stdio.h>
int main()
{
    union saving {
        short int one;
        char two[2];
    };
    union saving m;
    m.two[0] = 5;
    m.two[1] = 2;
    printf("%d, %d, %d\n", m.two[0], m.two[1], m.one);
}
Q29.

Given below are three implementations of swap() in C++:

(a) void swap(int a, int b) { int temp; temp = a; a = b; b = temp; }  called as swap(p, q);
(b) void swap(int &a, int &b) { int temp; temp = a; a = b; b = temp; }  called as swap(p, q);
(c) void swap(int *a, int *b) { int *temp; temp = a; a = b; b = temp; }  called as swap(&p, &q);

with int p = 0, q = 1 in main(). Which of these would actually swap the contents of p and q?

Q30.

Which of the following statements is/are True ? P : C programming language has a weak type system with static types. Q : Java programming language has a strong type system with static types.