Programming and Data Structure (Part 1) : Time: 60 Min

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Test  |  3.

73

Test

Programming and Data Structure (Part 1) Time: 60 min.

Directions for questions 1 to 30:  Select the correct alterna- else


tive from the given choices. if(∗P % 2 = = 0)
1. What is the behavior of following code? return ∗p + fun(p + 1, n – 1);
auto int I; else
int main( ) return ∗p – fun(p + 1, n –1);
{ }
} main( )
(A) Compiler error (B) No error {
(C) Linker error (D) Runtime error
int arr[ ] = {56, 48, 55, 10, 49, 14};
2. What is the output of following code: printf(“% d”, fun(arr, 6));
#define scanf “%S is a string” }
int main( )
Which of the following is the output of above function?
{ (A) 110 (B) –122
printf(scanf, scanf); (C) 114 (D) 108
} 5. Consider the function:
(A) is a string is a string int fun (int n)
(B) %S is a string is a string
{
(C) %S is a string %S is a string
(D) Syntax error static int i = 1;
if (n > = 5) return n;
3. void rec_fun (int n, int sum)
n = n + i;
{
i ++;
int k = 0, j = 0;
return fun (n);
if(n = = 0) return;
}
k = n%10; j = n/10;
sum+ = k;
The value returned by f (3) is
(A) 6 (B) 7
rec _fun(j, sum); (C) 8 (D) 9
printf(“%d\t”, k);
6. Which of the following code will change a lower case
}
letter to an upper case?
main ( ) (A) char C2 = (C1 > = ‘A’ & C1 < ‘Z’)?
{ ‘a’ + ‘C1’ – ‘A’: C1);
int a = 2048; sum = 0; (B) char C2 = (C1 > = ‘a’ & C1 < = ‘z’)?
‘A’ – ‘a’ + ‘C1’) : C1;
rec _fun(a, sum);
(C) char C2 = (C1 > = ‘a’ & & C1 < = ‘z’)?
printf(“%d”, sum); ‘A’ + ‘C1’ – ‘a’: C1;
} (D) char C2 = (C1 > = ‘A’ & & C1 < = ‘Z’)?
What does the above program print? ‘A’ – ‘C1’ + ‘a’: C1;
(A) 8 4 0 2 14 7. The following is a program to find the average length of
(B) 8 4 0 2 0 several lines of text. What should be the lines of code
(C) 2 0 4 8 18 corresponding to ‘SecA’ and ‘SecB’.
(D) 2 0 4 8 0 main( )
4. int fun (int ∗ p, int n) {int n, count = 0, sum = 0;
{ float avg;
if (n < = 0) return 0; secA
3.74 | Unit 3  •  Programming and data Structure

{ 11. main( )
count++; {
sum + = n; char fname[ ] = “TIME 4 EDUCATION”;
} time4(fname);
avg = (float) sum/count; }
} time4(char fname[5])
int linecount (void) {
{ fname + = 7;
char line [80]; printf(“%s”, fname);
int count = 0; fname = 2;
while (secB) printf(“%s”, fname);
{ }
count ++; What is the output of above code?
} (A) 4 EDUCATION
(B) EDUCATION
return (count);
(C) TIME 4 EDUCATION
} (D) EDUCATION ME 4 EDUCATION
(A) Sec A: while (n > 0) 12. What will be output of following code?
Sec B: line [count]! = 0
int main( )
(B) Sec A: while (linecount ( ) > 0)
Sec B: (line [count] = getch ( ) ! = ‘\n’) {
(C) Sec A: while ((n = linecount( ) > 0) extern int x;
Sec B: (line [count] = getch ( ) ! = ‘\n’) x = 13;
(D) None of these
printf (“%d”, x);
8. What is the meaning of following declaration? int(∗f1)
return 0;
( );
}
(A)  f1 is a function which returns a pointer to an integer
(A) 13
number.
(B) Vary from compiler
(B)  f1 is a pointer to a function which returns an integer (C) Linker error
number. (D) Undefined symbol
(C) f1 is a function which takes an integer pointer. 13. What is the output of the following code?
(D) f1 is a pointer to an integer number. main( )
9. Which of the following represents the statement: “x {
is a pointer to a group of one dimensional 20 element int x = y = z = 100;
arrays”.
int i;
(A) int ∗x[20]; (B) int ∗x[10] [20]; i = x > y < z;
(C) int ∗∗x[20]; (D) int (∗x) [20]; printf(“% d”, i);
10. What will be the output of the following code? }
int number[ ] = {18, 20, 22, 24};
(A) 0 (B) 1
main( )
(C) error (D) No output
{ 14. In the following code, how many times ‘while’ loop
int ∗q; will be executed?
q = number; int count = 0;

q + = 4; while (count < 32767)

printf(“%d”,∗q); count++;
(A) 32767
}
(B) 32766
(A) 24 (B) Compiler error (C) infinite times
(C) syntax error (D) –24 (D) varies from complier to compiler
Test  |  3.75

15. #define SUM(x)x + x ∗ x return 1;


#define DIF(x)x ∗ x – x if (r % 2 = = 0)
int main( ) return(rec_f2 (r/2)+ 2);

{ else return ((rec_f2(r – 1) + 3);

float y = SUM(5) /DIF(5); }


main( )
printf(“%f”, y);
{
}
(A) 1.5 (B) 0 printf (“%d”, rec_f2(7));
(C) 2 (D) 1 }
16. Which of the following is a correct description of void Which of the following is the output of above program?
(∗ ptr[10]) ( ) ; (A) 10 (B) 11
(A) ptr is an array of 10 pointers to functions returning (C) 13 (D) 0
type void. 21. int guest(int a);
(B) ptr is an array of 10 functions returning pointers int host(int b);
of type void.
main( )
(C) ptr is an array of 10 functions returning void ∗.
(D) ptr is an array of data elements of type void. {
17. int main( ) int p = 50, q = 100, r ;
{ for (r = 0; r < 2; r ++)
int p = 2, g = 2; {
printf(“ %d%d”, p < < g, p > > g); q = guest(p) + host(p);
} printf(“ %d”, q);
Output of above code is }
(A) 1 16 (B) 4 0 }
(C) 16 4 (D) 8 0 int guest (int a)
18. Which of the following is equivalent expression for P = {
a ∗ 16 + b/8;
int y;
(A) P = (a < < 4) + (b > > 2)
(B) P = (a > > 4) – (b < < 2) y = host(a);
(C) P = (a < < 4) + (b > > 3) return(y);
(D) P = (a < < 4) + (b < < 3) }
19. What is the output of the below code? int host (int a)
main( ) {
{ static int y = 0;
int I = 0, ∗j = &I; y = y + 1;
f1(j); return (a + y);
∗j = ∗j + 10; }
printf(“ %d%d”, I, j); The output of above code will be
} (A) 103 107 (B) 107 103
f1(int ∗k) (C) 110 107 (D) 107 110
{ 22. Choose the best matching between groups A and B:
∗k+ = 15; Group A Group B

} 1 Volatile P Queue
(A) 20 55 (B) 25 25 2 Function pointer Q Auto
(C) 45 55 (D) 35 35 3 Default R Guest and host
20. int rec_f 2(int r) 4 FIFO S Switch–case
{ (A) 1 – S, 2 – Q, 3 – R, 4 – P
if (r = = 1 || r= = 0) (B) 1 – Q, 2 – P, 3 – R, 4 – S
3.76 | Unit 3  •  Programming and data Structure

(C) 1 – Q, 2 – R, 3 – S, 4 – P Common Data for Questions 27 and 28:


(D) 1 – R, 2 – Q, 3 – P, 4 – S Consider the following code:
23. Which of the following expression represents the state- int f (int P)
ment: “P is a function that accepts a pointer to a char-
{
acter array”.
(A) int p(char ∗a[ ]); (B) int (∗p) (char (∗a)[ ]); if(P < = 0) return 1;
(C) int ∗p (char ∗a); (D) int p(char (∗a) [ ]); if(P% 10 = = 0)
24. void arr_fun(int [ ] [3]); return f(P – 2); //X
main( ) else
{ return f(P – 3); //Y
int x[3][3] = {{10, 20, 30}, {40, 50, 60}, }
{70, 80, 90}}; main( )
arr_fun(x); {
printf(“%d”, x[2][1]); printf(“ %d”, f(30));
} }
void arr_fun (int y[ ][3]) 2 7. What will be the output of above code?
{ (A) 10 (B) 50
++y; (C) 100 (D) 1
y[1][1] = 9; 28. What will be the output if the lines labeled X and Y are
changed as follows:
}
X : return 3 + f (P/2);
What is the output of the above code?
(A) 80 (B) 90 Y : retrun 2 + f (P/3);
(C) 70 (D) None of these (A) 4 (B) 6
(C) 8 (D) 10
25. #define F – 1
Common data for Questions 29 and 30:
#define T 1
1. float fn1(float n, int a)
#define N 0
2. {
main( )
3. float P, S;
{
int I;
if(N)
printf(“ %s”, “GOOD”); 4. for(S = x, P = 1, I = 1; P = P ∗ x ∗ x;
else 5. I < a; I ++)
if(F) S = S + P/(l);
printf(“ %s”, “MORNING”); 6. return (S);
else 7. }
printf(“ %s”, “GOOD NIGHT”); 8. int f(int x)
}
9. {
Output of above code will be
10. int f = 1;
(A) GOOD
(B) MORNING 11. for (int i = 1; i < = n; i++)
(C) GOOD MORNING 12. f = f ∗ i;
(D) GOOD NIGHT 13. return (f);
26. An external variable 14. }
(i) is defined once and declared in other functions. 29. Output of above code for fn1(2.1, 20) is
(ii) is globally accessible by all functions. x2 x4
(A) x + + + ...a + 2.1
(iii) cannot be static 2! 4 !
(iv) is defined after main( ) x − x3
(A) (i) and (ii) (B) (i), (ii) and (iii) (B) + ⋅a + 2.1
3!
(C) (ii), (iii) and (iv) (D) (i), (ii), (iii), (iv)
Test  |  3.77

S = S + P/f(I);
(C) x x2
1+ + + }
1! 2 !
What will be the approximation of f (x)?
x x3 x5
1+
(D) + + + ⋅a + 2.1 (A) 1 + x − x2 + x3… (B) x x3
1! 3! 5! 1− + −
1! 3!
0. When the statement numbered 4, 5, 6, 7 are replaced by
3
{for (S = 1, P = –x, I = 1; I < a; i++) x x 2 x3 x x 2 x3
(C)
1− + + +  (D)
1− + − +
P = P ∗ x ∗ x –1; 1! 2 ! 3! 1! 2 ! 3!

Answer Keys
1.  A 2. B 3. A 4. C 5. A 6. C 7. C 8. B 9. D 10. B
11. D 12. C 13. B 14. C 15. D 16. A 17. D 18. C 19. B 20. B
21. A 22. C 23. B 24. A 25. B 26. B 27. D 28. D 29. A 30. D

You might also like