1
Branch : CSE & IT Batch:Hinglish
WEEKLY TEST – 01
Subject : C Programming
Maximum Marks 20
Q.1 to 6 Carry ONE Mark Each
[MCQ] [MCQ]
1. #include <stdio.h> 4. #include < stdio.h>
int main(void){ void main()
float x; {
x = 7*2.0/2+10/3; int a = 2, b = –1, c = 0, d;
printf("%f", x); d = a -- || b ++ && c ++;
return 0; printf("%d%d%d%d", a, b, c, d);
} }
The value of a is ___
The output string is-
(a) 10 (b) 10.0
(a) 1–101 (b) –1110
(c) 10.33 (d) 11.0
(c) 1–111 (d) 111–1
[MCQ]
[NAT]
2. #include <stdio.h>
5. Consider the following program:
void main()
#include<stdio.h>
{
void main()
int a=0;
{
a=printf("Pankaj%dSharma",
int x=-2024;
printf("GATE Wallah"));
printf("%d", ~(x=x+5)) ;
printf("%d", a);
printf("%d", ~(x+1));
}
}
What will be the output when you compile and run the
The sum of the output values printed is __________.
above code?
(a) GATE Wallah10Pankaj14Sharma
(b) GATE WallahPankaj11Sharma13 [MCQ]
(c) GATE WallahPankaj11Sharma14 6. Consider the following program:
(d) GATE WallahPankaj10Sharma13 #include<stdio.h>
void main()
[NAT] {
3. Consider the following program. int a=0, b=1;
#include<stdio.h> a=(a=5)||(b=0);
void main() printf("%d", a);
{
int a; printf("%d", b);
a=21>24>17>-10<8>-1>-5!=0; }
printf("%d",a); The output is:
} (a) 50 (b) 51
The output is ___________. (c) 11 (d) 10
2
Q.7 to 13 Carry TWO Mark Each
[MCQ] [MSQ]
7. What will be the output of the C program? 10. If the final value of a = 5, which of the following are
#include<stdio.h> invalid combinations?
int main() a=p>q?r<q?p:q:r>q?p:r
{ (a) p = 5, q = 10, r = 9
int a = 3, b = 3, c = 0, d = 1, m; (b) p = 10, q = 5, r = 4
m = a-- || b++ && c++ || d--;
(c) p = 5, q = 9, r = 10
printf("%d %d %d %d %d", a, b, c, d, m);return 0;
(d) p = 10, q = 9, r = 5
}
(a) 2 3 1 1 1
(b) 4 4 1 4 1 [MCQ]
(c) 4 4 1 4 0 11. Consider the following program.
(d) 2 3 0 1 1 #include <stdio.h>
int main()
[NAT] {
8. Consider the following program. char ch=-143;
#include<stdio.h> printf("%c", ch);
void main() return 0;
{ }
int a; The output is-
a = printf(“Pankaj Sharma”) && (a) w (b) q
printf(“Wallah”) || printf(“GATE”); (c) u (d) Garbage
printf(“%d”, a);
} [NAT]
The number of characters printed is ______. 12. Consider the following program.
#include <stdio.h>
[MCQ] int main()
9. Consider the following program: {
#include<stdio.h> int c=32780;
void main() printf("%d", c);
{ return 0;
int a=2023; }
printf("%d%d%d", a!=2024, a=2021, a==2021); (Assume the size of integer is specified as of 2 bytes.)
} The output is ________.
The output is-
(a) 120210 [MSQ]
(b) 020211 13. Which of the following are valid declarations?
(a) unsigned a;
(c) 120211
(b) unsigned long a;
(d) 020231
(c) unsigned long long int a;
(d) short a;
3
Answer Key
1. (b) 8. (20)
2. (c) 9. (a)
3. (1) 10. (a, b, d)
4. (a) 11. (b)
5. (4035) 12. (-32756)
6. (c) 13. (a, b, c, d)
7. (d)
4
Hints and Solutions
1. (b) ~(x + 1) ~(–2019 + 1) = – (–2018 + 1) = 2017
x = 7*2.0/2+10/3; Sum of the values printed = 2018 + 2017 = 4035.
= 14.0/2 + 10/3
= 7.0+3 6. (c)
= 10.0 int a=0, b=1;
x is a float variable, a=(a=5)||(b=0);
so, x = 10.0 // Assignment operator assigns and returns the assigned
value. Here, short-circuiting will be applied. Since the
2. (c) logical operator is OR, if the first part is true, second
int a=0; part is not evaluated at all. Hence, b=1, a=1.
a=printf("Pankaj%dSharma", printf("GATE Wallah")); printf("%d", a);//1 is printed
// printf prints and returns an integer equal to the printf("%d", b);//1 is printed.
number of characters printed. Inner printf is executed
first here. 7. (d)
printf("%d", a); m = a-- || b++ && c++ || d--
Output: GATE WallahPankaj11Sharma14 3 || (rest is not evaluated)
=1
3. (1) (d) 2 3 0 1 1 is correct
a = 21>24>17>-10<8>-1>-5!=0
0 > 17 0 > -10 8. (20)
1<8 printf prints and returns an integer equal to the number
0>–1 of characters printed.
1 > -5 Due to short-circuiting, printf(“GATE”) is not
1!=0 executed. Since the logical operator is OR, if the first
1 part is true, second part is not evaluated at all.
a=1 Output: Pankaj SharmaWallah1
4. (a) 9. (a)
d = a -- || b ++ && c ++; The expressions are evaluated from right to left but are
d = a -- || (b ++ && c ++); printed from left to right.
// post decrement is used, so the value used is a=2; a= =2021 is equivalent to 2023= =2021. So, it evaluates
d = 2 || (b++ & c++); to 0.
↳ never evaluated a=2021. Assignment operator assigns the value and
d=1 returns the assigned value.
but because of post decrement, a becomes 1. a=2021. So, a!=2024 evaluates to 1.
Output: 1 -1 0 1 Output: 120210
10. (a, b, d)
5. (4035) The only valid combination is (c): p = 5, q = 9, r = 10
x = x + 5 x = –2024 + 5 = –2019
~(x) ~(–2019) = – (–2019 + 1) = 2018
5
Unsigned value for –143= 256 – 143 = 113.
Hence, ‘q’ is printed.
12. (–32756)
32780 is 13 steps ahead of 32767. After 32767, 13 steps
are counted from –32768(including 32768) as
Printed value = –32756.
a=5
All other combinations are invalid. 13. (a, b, c, d)
11. (b) All are valid declarations.
For more questions, kindly visit the library section: Link for web: https://smart.link/sdfez8ejd80if
PW Mobile APP: https://smart.link/7wwosivoicgd4