C Programming _ Weekly Test 01 - Test Paper
C Programming _ Weekly Test 01 - Test Paper
[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
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
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