0% found this document useful (0 votes)
4 views

C Programming _ Weekly Test 02 - Test Paper

This document is a weekly test for C Programming with multiple-choice questions (MCQs) and numerical answer type (NAT) questions. It includes programming scenarios, expected outputs, and answer keys for each question. The test covers various concepts in C programming, including loops, conditionals, and data types.

Uploaded by

Sachin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

C Programming _ Weekly Test 02 - Test Paper

This document is a weekly test for C Programming with multiple-choice questions (MCQs) and numerical answer type (NAT) questions. It includes programming scenarios, expected outputs, and answer keys for each question. The test covers various concepts in C programming, including loops, conditionals, and data types.

Uploaded by

Sachin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1

Branch : CSE & IT Batch:Hinglish


WEEKLY TEST – 02
Subject : C Programming
Maximum Marks 20

Q.1 to 5 Carry ONE Marks Each


[MCQ] return 0;
1. #include <stdio.h> }
int main() When x=5, the character printed is-
(a) e (b) G
{
(c) Garbage value (d) E
int i=9;
for(--i; i--; --i){ [MCQ]
printf("%d\t", i); 3. #include <stdio.h>
if(i==1) break; int main()
} {
return 0; int a,i;
} a= 12.4/5+33.2/2*5-5;
The output is- for(i=a; i<90;i=i+3)
(a) 8 5 2 1 (a) 7 6 4 3 1
{
(c) 8 6 4 2 1 (d) 7 5 3 1
printf("%c\t", i+32);
[MCQ]
}
2. #include <stdio.h>
return 0;
int main(void){
}
int x ;
scanf("%d", & x); The output is-
switch(x)
(a) p s v y (a) K L M N O
{
(c) k n q t w (d) P U V W
case 0: x = x + 1;
break;
default: x = x - 1;
case 1: x = x + 99; [MCQ]
break; 4. #include<stdio.h>
case 2: x = x + 96; int main()
break;
} {
printf("%c", x-32); int i=2023, j=2;
2

for(;j<i;j*=8) (b) 1
{ (c) Infinite Loop
i+=1; (d) 2 4
printf("GATE Wallah 2023\n");
} [MCQ]
return 0;
6. #include <stdio.h>
}
int main()
The number of times ‘GATE Wallah 2023’ is printed {
is-
int a = 10 > 9 ? 0 ? 3 : -2 : 5;
(a) 3 (b) 2
(c) 4 (d) 5 if(a = a + 1)
printf("GATE 2023");
[MCQ]
else
5. #include<stdio.h>
printf("GATE WALLAH");
void main()
{ return 0;
int x=5;
}
if(printf("%d",x>>1)-3)
for(;x--;x--) break; The output is-
else; (a) GATE 2023
printf("\t%d", x); (b) GATE WALLAH
}
(c) Compiler error
The output is- (d) Garbage value
(a) Compiler Error
Q.7 to 13 Carry TWO Marks Each
[NAT] break;
7. Consider the following program: }
#include<stdio.h> j++;
int main() printf("%d\n",p);
{ }
int p,j=0; return 0;
for(p=2;p<=100 && j<3;p*=2){ }
switch(p+j){ The sum of the values printed is ________________
case 1: p+=3;
break;
[NAT]
case 2: p+=5; 8. #include <stdio.h>

break; int main()

case 3: p+=7; {

default: p+=8; int i=printf("best hai GATE Wallah");


while(i>=3){
3

if(i%3!=0) i=i-5; [NAT]


else i=i+2; 11. #include<stdio.h>
printf("Pankaj Sharma\n");
int main()
}
return 0; {
int a=0, b=1;
}
while(++a<=5){
The number of times printf() is executed is______. do{
b+=2;
[MCQ] }while(b++<=10);
9. #include <stdio.h> }
int main() return 0;
}
{
int i, j=4, k=3; The sum of the values of a and b is ______.
i=j++<--k?++j:k--;
for(++i; ++i; ++i){ [MSQ]
printf("%d\t", i); 12. #include <stdio.h>
if(i>8) break;
} int main()
return 0; {
int x=-5;
} do
The output is- {
printf("%d\t", ~(x+2));
(a) 2 4 6 8 (a) 4 6 8 x++;
(c) 4 6 8 10 (d) 2 4 6 }while(~(x+1)%2==0);
printf("%d", x);
[MCQ] return 0;
10. #include<stdio.h> }
int main() Which of the following values will be displayed in
{ the output?
int a=2, b=4; (a) 2 (b) 1
while(a++<=b--); (c) –3 (d) – 4
printf("%d\t", a);
printf("%d", b); [MSQ]
return 0;
13. #include <stdio.h>
}
int main()
The output is –
{
(a) 4 2 (b) 4 1 int i, n, count=0;
(c) 5 2 (d) 5 1 for(i=1;i<=n;i=i*3)
count=count+i;
printf("%d", count);
return 0;
}
Which of the following CANNOT represent the final
value of the COUNT variable?
4

n 1
(a) 3n (b)
2
(c) lon3n (d) log3log3n
5

Answer Key

1. (d) 9. (c)
2. (b) 10. (d)
3. (a) 11. (31)
4. (c) 12. (a, b, c)
5. (d) 13. (a, b, c, d)
6. (a)
7. (81)
8. (12)

6

Hint & Solutions


1. (d) printf( ) → executed
Sol. for (--i; i --; --i){ j = 128
  
8 8 6 128 < 2025 → true
6 4 i = 2026;
4 2 printf( ) → executed
2 j = 1024
printf(“%d\t”, i);//7 5 3 1
1024 < 2026 → true
if(i==1) break; //Loop terminated
i = 2027;
} printf( ) → executed
Output is : 7 5 3 1 j = 8192
8192 < 2027 → false; //Loop terminated.
2. (b)
Sol. When, x=5, default is executed. As no break 5. (d)
statement is there after default, case 1 is also Sol. x=5
evaluated.
if(printf("%d",x>>1)-3)
x=5-1=4 5>>1= 2
x=4+99=103 printf() prints and returns the number of characters
it successfully printed. 2 is printed and printf()
Printed character is the character with ASCII (103- returns 1.
32) i.e 71. Condition is evaluated as-(1-3) = -2 i.e. TRUE.
for(;x--;x--) break; is evaluated.
3. (a) ↓
a = 12.4/5+33.2/2*5-5 5
Condition is True. x is decremented to 4. Then
a = 80.48
break is executed.
⸪ a is integer printf("\t%d", x); //4 is printed.

 a = 80 Output: 2 4

The for loop converts each character to lower case


6. (a)
corresponding to the ASCII values.
Sol. a = 10 > 9 ? 0 ? 3 : -2 : 5;
Output ASCII : (80 + 32) (83 + 32) (86 + 32)
10>9 is TRUE and 0 is False, so a=-2
(89+32)
Now the assignment operator assigns and returns the
Output characters : p s v y
value. So, a=-2+1=-1; Hence, condition becomes
true, “GATE 2023” is printed.
4. (c)
Sol.for (j = 2; j < i ; j = j * 8) 7. (81)
P 2 7 14 22 44 52 104 j 0 1 2 3
2 < 2023 → true Sol.
switch (2 + 0) –
i = 2024;
printf( ) → executed case 2: ✓ p + = 5
j = 16 p = 7 * 2 = 14 → 7 is printed
switch (14 + 1) –
16 < 2024 → true
default: ✓ p += 8 → 22 printed
i = 2025;
7

p = 22 * 2 = 44 4 < = 2 → True
switch (44 + 2) –  Post – decrement / increment operator assigns and
default: ✓ p += 8 → 52 is printed then decrements / increments.
52 * 2 = 104  a 5 b 1
104 < = 100 → false  Output is : 5 1
 sum of printed values = 7 + 22 + 52 = 81
11. (31)
8. (12) a 0 1 2 3 4 5 6
Sol. printf() prints and returns the number of characters
it printed. “best hai GATE Wallah” is printed. b 1 3 4 6 7 9 10 12 13 15 16 18 19 21 22 24 25

i=20; while (++a < = 5)


{
The iteration while() executes for i=20, 15, 17, 12,
1 < = 5 → True
14, 9, 11, 6, 8, 3, 5.
2 < = 5 → True
“Pankaj Sharma” is executed for the above 11 do { 3 < = 5 → True
values of i. 4 < = 5 → True
5 < = 5 → True
The number of times printf() executed is 12.
6 < = 5 → False

9. (c) b = b + 2;
Sol. i=j++<--k?++j:k--; //4<2-> TRUE, so, k—is 1+2→3 10 + 2 → 12 19 + 2 = 21
evaluated. i takes the value 2. 4+2→6 13 + 2 → 15 22 + 2 = 24
i = 2, k=1, j=5; 7+2→9 16 + 2 → 18
for (++i; ++i; ++i) }
while (b ++ < = 10);
{ 3 < = 10 → true
  6 < = 10 → true
9 < = 10 → true
34 5
12 < = 10 → False
67 15 < = 10 → False
18 < = 10 → False
89
21 < = 10 → False
10 24 < = 10 → False
printf (“%d\t”, i); // 4 6 8 10 Final value –

if(i > 8) break;  a 6 b 25

Sum = a + b = 6 + 25 = 31
10 > 8  break
} 12. (a, b, c)

Output: 4 6 8 10 ~(x+2) i.e -(-5+2+1)=2 is printed.


x++; //x=-4
10. (d) ~(x+1)=2. (~(x+1)%2==0) condition becomes
Sol. TRUE.
a 2 3 4 5 b 4 3 2 1 ~(x+2) i.e -(-4+2+1)=1 is printed.
x++; //x=-3
while (a++ < = b – –);
~(x+1)=1. (~(x+1)%2==0) condition becomes
2 < = 4 → True FALSE.
3 < = 3 → True
8

Loop terminates. 13. (a, b, c, d)


printf("%d", x);//-3 is printed. None of the options are correct.
Output: 2 1 -3



For more questions, kindly visit the library section: Link for web: https://smart.link/sdfez8ejd80if

PW Mobile APP: https://smart.link/7wwosivoicgd4

You might also like