0% found this document useful (0 votes)
24 views5 pages

Spring 2024 CS102 Soln

Uploaded by

khushiyadav45123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views5 pages

Spring 2024 CS102 Soln

Uploaded by

khushiyadav45123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Indian Institute of Technology Patna

Date: 23 Feb 2024


Mid Semester Examination: CS102-Programming & Data Structure
Duration: 2 hours Full Marks 30*4=120
Instruction: All questions carry four marks and one mark will be deduced for each wrong answer. The correct option for
all the questions should be written on the table given below. Please assume that all the required header files are included
in the code snippet for all questions. Use the answer booklet for solving the problems. No doubts would be entertained
during the examination.

Name: Roll No.:

# Correct Ans (C): # Incorrect Ans (I): Total (4 ∗ C − I):

Evaluated By: Verified By:

1. How many times will PDS be printed? 3. What will be the output for the following C code snippet?

#if a == 0
int main() #define b 5
{ #else
int i = 2048; #define b 10
for (; i; i >>= 1) #endif
printf("PDS\n");
return 0; int main()
} {
printf("%d", b);
return 0;
}
(A) 11 (B) 12 (C) 22 (D) Infinite
(A) 0 (C) 10
2. What will be the output of the following code snippet? (B) 5 (D) Compilation error

4. Write the output of the program


int main()
void main()
{
{
int x = 0;
int a, b = 10, c = 9;
if(x < 1)
a = b == c;
printf("Hello");
printf("%d", a);
else;
return 0;
printf(" World ");
}
}
(A) Hello (C) Hello World
(A) 0 (C) 9
(B) World (D) Syntax error
(B) 1 (D) Compilation Error

1
5. Predict Output (D) 5 6 7 8 9 10 11 12 13 14

void modifyString(char str[]) 8. Predict Output


{
for (int i = 0; i < strlen(str); i++) int main() {
{ struct s1
if (str[i] >= ‘a’ && str[i] <= ‘z’) {
str[i] = str[i] - 32; char z[10];
} int i;
printf("%s\n", str); };

} static struct s1 a[] =


{
int main() {"Delhi", 1},
{ {"Patna", 2},
char str[] = "CS102 PDS"; {"Mumbai", 3}
modifyString(str); };
return 0;
} struct s1 ptr;
printf("%s %s %s ",a[0].z,a[0+2-1+1-2].z,a[1].z);
(A) CS102 (C) CS102 PDS return 0;
}
(B) PDS (D) Compilation Error
(A) Delhi Patna Mumbai
6. Predict Output (B) Patna Mumbai Mumbai
(C) Delhi Delhi Patna
int main() (D) Compilation error
{
int tally=0; 9. Predict Output
for(;;)
int main()
{
{ int a=14, b=10;
if(tally==10)
while(a<20 || b<15)
break;
{ ++a;
printf("%d ",++tally);
b++;
}
if(a>=16 && a<=18)
return 0;
{
}
continue;
}
(A) 0 1 2 3 4 5 6 7 8 9 10 (C) 0 1 2 3 ... infinite times printf("%d %d ", a,b);
(B) 1 2 3 4 5 6 7 8 9 10 (D) 1 2 3 4 5 6 7 8 9 }
return 0;
7. Predict Output }

int main()
(A) 15 11 19 16 20 15 (C) 15 11 19 15 16 20
{
int j = 1, num1 = 4; (B) 15 11 19 15 20 16 (D) 15 11 19 20 15 16

while(++j <= 10) 10. Predict Output

{
void main()
num1++;
{
printf("%d\n", num1);
int a = 10, b=5;
}
float a = a+b;
printf("%f", a);
}
}
(A) 4 5 6 7 8 9 10 11 12 13
(B) 5 6 7 8 9 10 11 12 13 (A) 15.0000 (C) 10.5
(C) 4 5 6 7 8 9 10 11 12 13 14 (B) 10 (D) Compilations Error

2
11. Predict Output 14. Predict Output

void main() int main ()


{ {
char a[] = "ABCD"; int i, j;
char b[] = "PQRST"; int a [8] = {1, 2, 3, 4, 5, 6, 7, 8};
for(i = 0; i < 3; i++) {
strcpy(b, a); a[i] = a[i] + 1;
strcpy(a, b); i++;
printf("%s", a); }
} i--;
for (j = 7; j > 4; j--) {
(A) ABCD (C) PQRSTABCD int i = j/2;
a[i] = a[i] - 1;
(B) PQRST (D) PQRST ABCD
}
printf ("%d, %d", i, a[i]);
12. Consider the following C-function in which a[n] and b[m] are }
two sorted integer arrays and c[n + m] be another integer
array. (A) 2, 3 (B) 2, 4 (C) 3, 2 (D) 3, 3

void xyz(int a[], int b [], int c[]) 15. Consider the same recursive C function that takes two ar-
{ guments
int i, j, k;
i = j = k = O; unsigned int foo(unsigned int n, unsigned int r)
while ((i<n) && (j<m)) {
if (a[i] < b[j]) if (n > 0)
c[k++] = a[i++]; return (n % r + foo(n / r, r));
else else
c[k++] = b[j++]; return 0;
} }

Which of the following condition(s) hold(s) after the termi- What is the return value of the function foo when it is called
nation of the while loop? as foo(513, 2)?
(a) j < m, k = n + j − 1, and a[n − 1] < b[j] if i = n
(A) 9 (B) 8 (C) 5 (D) 2
(b) i < n, k = m + i − 1, and b[m − 1] <= a[i] if j = m

(A) only (a) 16. What is the return value of f(p,p), if the value of p is initial-
ized to 5 before the call? Note that the first parameter is
(B) only (b) passed by reference, whereas the second parameter is passed
(C) either (a) or (ii) but not both by value.
(D) neither (a) nor (b)
int f (int &x, int c) {
13. Predict Output c = c - 1;
if (c==0) return 1;
x = x + 1;
int main () {
return f(x,c) * x;
int sum = 0, maxsum = 0, i, n = 6;
}
int a [] = {2, -2, -1, 3, 4, 2};
for (i = 0; i < n; i++) {
(A) 3024 (B) 6561 (C) 55440 (D) 161051
if (i == 0||a[i]<0||a[i]<a[i - 1])
{
if (sum > maxsum) maxsum = sum;
sum = (a [i] > 0) ? a [i] : 0;
}
else sum += a [i];
}
if (sum > maxsum) maxsum = sum ;
printf ("%d\n", maxsum);
}

(A) 9 (B) 8 (C) 7 (D) 6

3
17. Consider the following C function. int f1(void);
int f2(void);
int fun (int n){ int f3(void);
int x = 1, k; int x=30;
if (n == 1) int main()
return x; {
for (k = 1; k < n; ++k) int x=1;
x = x + fun(k) * fun(n-k); x += f1() + f2 () + f3() + f2();
return x; printf("%d", x);
} return 0;
}
The return value of fun(5) is . int f1() { int x = 25; x++; return x;}
int f2() { static int x = 50; x++; return x;}
int f3() { x *= 10; return x;}
(A) 0 (B) 21 (C) 51 (D) 71
(A) 50 (B) 85 (C) 230 (D) 430
18. Consider the following program
21. Predict Output
int main()
{ int main()
int i, j, k = 0; {
j=2 * 3 / 4 + 2.0 / 5 + 8 / 5; int a = 10, b = 10;
k-=--j; printf(a > b ? "A" : a > b ? "B" : "C");
for (i=0; i<5; i++) return 0;
{ }
switch(i+k)
{ (A) A (B) B (C) C (D) A B C
case 1:
case 2: printf("\n%d", i+k);
22. Predict Output
case 3: printf("\n%d", i+k);
default: printf("\n%d", i+k);
int main()
}
{
}
int i = 0;
return 0;
for (i; i < 4; i++)
}
switch (i)
{
The number of times printf statement is executed case 0:
is . printf("A ");
break;
(A) 8 (B) 9 (C) 10 (D) 11 case 1:
printf("B ");
19. Predict Output default:
printf("C ");
}
int main()
{
return 0;
for (int i = 1; i < 21; i++)
}
{
if (i % 3 != 0)
(A) A B C C (C) A B C C C
continue;
printf("%d ", i); (B) A B C B C C (D) A B C
}

return 0;
}

(A) 3 6 9 12 15 18 21 (C) 6 9 12 15 18 21
(B) 3 6 9 12 15 18 (D) 2 4 6 8 10

20. Predict Output

4
23. Predict Output (A) 5 (C) 8
(B) 11 (D) Compilation error
int main()
{
int i = 0; 27. Every C Variable must have.?
A: i++;
B: printf("%d ", i++);
(A) Type
if (i < 10) goto A;
return 0; (B) Storage Class
} (C) Both Type and Storage Class
(A) 0 2 4 6 8 (C) 0 2 4 6 8 10 (D) Either Type or Storage Class
(B) 1 3 5 7 9 (D) 0 1 3 5 7 9
28. Which of the following is the fastest memory?
24. Predict Output
(A) Random Access Mem- (C) Register Memory
int main() ory
{ (B) Read Only Memory (D) Cache Memory
float x=0.9;
if(x==0.9)
printf("if"); 29. Predict Output
else if (x==0.9f)
printf("else if"); int main()
else {
printf("else"); char ch[10];
} int inum;
float fnum;
(A) if (C) else
(B) else if (D) Compilation error char buffer[50] = "IITP 1510.2";
sscanf (buffer, "%s%d%f", ch, &inum, &fnum);
25. Which of the following is true about the name of 1D-Array?
printf("%s ", ch);
(A) It holds the address of the first element of array. printf("%d ", inum);
(B) It can be incremented or decremented using pointer printf("%f", fnum);
arithmetic. }
(C) Both (A) and (B)
(D) None of these (A) IITP 1510 0.200000 (C) IITP 151 0.200000
(B) IITP 15 10.200000 (D) Syntax Error
26. Predict Output

int main() 30. Which of the storage classes limits the re-initialization of a
{ variable?
int a=5;
a=(a+1, a+2, a+3);
printf("%d",a); (A) auto (C) extern
} (B) static (D) register

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy