You are on page 1of 9

# 3005 Programming 90 minutes

Question - 1
C

## Consider the following code: function modify(w,u)

{
w=w+2
u=u-3
return (w - u)
}
function calculate( )
{
integer a = 10, b = 20, c
c = modify(a, b);
print a
print space
print b
}
Assume that a was passed by value and b was passed by
reference. What will be the output of the program on executing
function calculate( ) ?

12 17

10 17

12 20

10 20

Question - 2
c

integer

character

boolean

array

Question - 3
c

## The construct if (condition) then A else B is for which of the

following purposes?

Decision-Making
iteration

recursion

Object Oriented
Programming

Question - 4
c

Decision-Making

iteration

recursion

none of
these

Question - 5
c

## An integer X is saved as an unsigned 8-bit number,

00001011.What is X?

22

11

10

none of
these

Question - 6
c

## Consider the following code: function modify(y,z)

{
y = y + 1;
z = z + 1;
return y - z
}
function calculate( ) {
integer a = 5, b = 10, c c = modify(a, b);
print a
print space
print c
}
Assume that a and b were passed by value. What will be the
output on executing function calculate( )?
( 11 -5)

(10 -5)

(6 -5)

(5 -5)

Question - 7
c

## What does the following function do? function operation (int a,

int b)
{
if (a < b)
{ return operation(b, a) } else
{ return a }
}

(a,b)

(a,b)

Loops
forever

Question - 8
c

## Consider following given code and predict its output. main()

{
int num[ ] = {1,4,8,12,16};
}
int *a,*b; int i; a=num;
b=num+2; i=*a+1;
printf("%d,%d,%d\n",i,*a,*b);

2,1,8

4,1,8

4,4,8

2,4,8

Question - 9
c

## Surya is making a questionnaire of True-false questions. She

wants to define a data-type which stores the response of the
candidate for the question. What is the most-suited data type for
this purpose?

integer

boolean

float

character

Question - 10
c

## What will be the output of the following pseudo-code

statements: integer a = 456, b, c, d =10
b = a/d
c=a-b
print c

410

410.4

411.4

411

Question - 11
c

## Lavanya wants to find the smallest number out of 26 inputted

numbers. How many minimum comparisons he has to make?

25

13

26

52

Question - 12
c

## What is the output of the following code statements? The

compiler saves the first integer at the memory location 4062.
Integer is one byte long.
integer a
pointer b
a = 20
b = &a print *b
4062

4063

20

10

Question - 13
c

## What is the output of the following code statements? The

compiler saves the first integer at the memory location 4165 and
the rest at consecutive memory spaces in order of declaration.
Integer is one byte long.
integer a, b
pointer c, d a = 30
c = &a
b = *c
a = a + 10 print b

30

4165

40

4166

Question - 14
c

Shrishti writes the code for a function that computes the factorial
of the inputted number n.â​¨function factorial(n)â​¨{
if(n equals 1) return 1
else
-- MISSING STATEMENT -- end
}
Fill in the missing statement.

return factorial(n-1)

return n*factorial(n)

return n*(n-1)

return n*factorial(n-1)

Question - 15
c
Consider the following code: function modify(a,b)
{
integer c, d = 2
c = a*d + b
return c
}
function calculate( ) {
integer a = 5, b = 20, c integer d = 10
c = modify(a, b); c=c+d
print c
}
Assume that a and b were passed by value. What will be the
output of the function calculate( ) ?

80

40

32

72

Question - 16
c++

## Return type of rand() function is:

short

int

char

float

Question - 17
c++

include <iostream>
using namespace std;
namespace first
{
int var = 5;
}
namespace second
{
double var = 3.1416;
}
int main ()
{
int a;
a = first::var + second::var;
cout << a;
return 0;
}

8.31416
8

compile time
error

Question - 18
c++

from outside

## private and protected member can be accessed

anywhere

both a & b

None of the
mentioned

Question - 19
c++

#include<stdio.h>
union student
{
int y[34];//Consider int as 2 byte
char var2[7];//Consider char as 1 byte

char arr[8];
char ch[5];
};
int main()
{
union student st;
printf("%d", sizeof(union student));
return 0;
}

126

136

146

142

Question - 20
c++
#include <iostream>
using namespace std;
int main()
{
enum channel {star, sony, zee};
enum symbol {hash, star};
int i = 0;
for (i = star; i <= zee; i++) {
printf("%d ", i);
}
return 0;
}

12

123

Error

012

Question - 21
Merge them

## Merge two arrays A, B of size N and M respectively into the third

array C of size N+M. Arrays are assumed to be sorted
in ascending order.

For example:
A -> 1,2,3
B -> 4,5,6
Then, C -> 1,2,3,4,5,6

Input:
NM
Space separated N elements of A
Space separated M elements of B

Output:
Space separated N+M elements of C

Example:
Input:
45
1245
36789

Output:
123456789

Question - 22
Zero sum

Find the two elements from the given array A of size N such that
their sum is closest to zero.

For example,
A -> 1,2,-1,5
Then the two elements whose sum is closest to zero are 1,-1

Input Format:
First line contains N (size of the array A)
Second line contains N elements of array A

Output Format:
Space separated elements

Example:
Input:
4
1 2 -1 5

Output:
1 -1

Question - 23
Next Greater

## Given an array A of size N, replace every element with the next

greatest element (greatest element on the right side) in the
array. If there are no numbers to the right of an element, or
there are no greater number to the right of the element,
then replace it with -1.

## For example, if the array is {16, 17, 4, 3, 5, 2}, then it should be

modified to {17, 5, 5, 5, 2, -1}.

Input:
First line contains N, size of the array A
Space separated N elements of A

Output
Space separated processed array

Example:
Input:
6
16 17 4 3 5 2

Output:
17 5 5 5 2 -1