2/12/24, 2:47 PM GATE_Weekly Test-01_DPP
GATE
Weekly Test-01
Computer Science & Information Technology
C Programming
Q1 #include <stdio.h> (A) a ≤ b
int main(void){ (B) b > c
float x; (C) b ≥ c and a ≤ b
x = 7*2.0/2+10/3; (D) a > b and b ≤ c
printf("%f", x);
Q5 Consider the following program:
return 0;
#include<stdio.h>
}
void main()
The value of a is ___
{
(A) 10 (B) 10.0
int x=-2024;
(C) 10.33 (D) 11.0
printf("%d", ~(x=x+5)) ;
Q2 A C program contains the declaration and printf("%d", ~(x+1));
initial assignments }
int i = 8, j = 5 The sum of the output values printed is
float x = 0.005, y = –0.01; __________.
char c = ‘c’, d = ‘d’;
Q6 Consider the following program:
the values of arithmetic expression
#include<stdio.h>
(2*(i/5) + (4* j – 3)) % (i – j – 2) is
void main()
(A) 19 (B) 15
{
(C) 0 (D) 1
int a=0, b=1;
Q3 Consider the following program. a=(a=5)||(b=0);
#include<stdio.h> printf("%d", a);
void main() printf("%d", b);
{ }
int a; The output is:
a=21>24>17>-10<8>-1>-5!=0; (A) 50 (B) 51
printf("%d",a); (C) 11 (D) 10
}
Q7 What will be the output of the C program?
The output is ___________.
#include<stdio.h>
Q4 Consider the following program fragment int main()
if (a > b) {
if(b > c) int a = 3, b = 3, c = 0, d = 1, m;
S1; m = a-- || b++ && c++ || d--;
else printf("%d %d %d %d %d", a, b, c, d, m);
S2; return 0;
S2 will be executed if }
Android App | iOS App | PW Website
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 1/5
2/12/24, 2:47 PM GATE_Weekly Test-01_DPP
GATE
(A) 2 3 1 1 1 (B) 4 4 1 4 1 printf("%d", c);
(C) 4 4 1 4 0 (D) 2 3 0 1 1 return 0;
}
Q8 Consider the following program:
(Assume the size of integer is specified as of
#include<stdio.h>
2 bytes.)
void main()
The output is ________.
{
int a=2023; Q10 What is the output of the following ‘C’
printf("%d%d%d", a!=2024, a=2021, program?
a==2021); main ()
} {
The output is- int i = 32, k, l, m, j = 0 × 20;
(A) 120210 (B) 020211 k = i|j;
(C) 120211 (D) 020231 l = i & j;
m = k ^ l;
Q9 Consider the following program.
printf(“%d%d%d%d%d”, i, j, k, l, m);
#include <stdio.h>
int main()
}
{
(A) 32 32 32 32 0 (B) 0 0 0 0 0
int c=32780;
(C) 0 32 32 32 32 (D) 32 32 32 32 32
Android App | iOS App | PW Website
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 2/5
2/12/24, 2:47 PM GATE_Weekly Test-01_DPP
GATE
Answer Key
Q1 (B) Q6 (C)
Q2 (C) Q7 (D)
Q3 1 Q8 (A)
Q4 (D) Q9 –32756
Q5 4035 Q10 (A)
Android App | iOS App | PW Website
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 3/5
2/12/24, 2:47 PM GATE_Weekly Test-01_DPP
GATE
Hints & Solutions
Q1 Text Solution: Hence S2 will be executed when first
x = 7*2.0/2+10/3; condition is true and second is false.
= 14.0/2 + 10/3 Hence, if (a > b) and (b ≤ c), S2 will executed.
= 7.0+3 Q5 Text Solution:
= 10.0 x = x + 5 → x = –2024 + 5 = –2019
x is a float variable, ~(x) → ~(–2019) = – (–2019 + 1) = 2018 ~(x + 1) →
so, x = 10.0 ~(–2019 + 1) = – (–2018 + 1) = 2017
Sum of the values printed = 2018 + 2017 = 4035.
Q6 Text Solution:
int a=0, b=1;
a=(a=5)||(b=0);
// Assignment operator assigns and returns the
assigned value. Here, short-circuiting will be
Q2 Text Solution: applied. Since the logical operator is OR, if the
(2* (8/5) + (4* 5 – 3)) % (8 – 5 –2) first part is true, second part is not evaluated at
(2* 1 + 17) % 1 all. Hence, b=1, a=1.
19% 1 printf("%d", a);//1 is printed
0 printf("%d", b);//1 is printed.
Q3 Text Solution: Q7 Text Solution:
a = 21>24>17>-10<8>-1>-5!=0 m = a-- || b++ && c++ || d--
0 > 17 ⇒ 0 > -10 3 || (rest is not evaluated)
1<8 =1
0>–1 (d) 2 3 0 1 1 is correct
1 > -5 Q8 Text Solution:
1!=0 The expressions are evaluated from right to left
1 but are printed from left to right.
a=1 a= =2021 is equivalent to 2023= =2021. So, it
Q4 Text Solution: evaluates to 0.
if(a > b) a=2021. Assignment operator assigns the value
{ and returns the assigned value.
if(b > c) a=2021. So, a!=2024 evaluates to 1.
{ Output: 120210
S1; Q9 Text Solution:
} 32780 is 13 steps ahead of 32767. After 32767, 13
else steps are counted from –32768(including 32768)
{ as
S2; Printed value = –32756.
}
Q10 Text Solution:
}
i = 32
Android App | iOS App | PW Website
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 4/5
2/12/24, 2:47 PM GATE_Weekly Test-01_DPP
GATE
j = 0 × 20
⇒ 2 × 161 + 0 × 160 ⇒ 32
k = i|j ⇒ 32 16 8 4 2 1
i⇒1 0 0 0 0 0
j ⇒1 0 0 0 0 0
or
1 0 0 0 0 0 ⇒ 32
k = 32
l=i&j
i⇒1 0 0 0 0 0
j⇒1 0 0 0 0 0
AND ⇒
1 0 0 0 0 0 ⇒ 32
l = 32
m = k^l;
k⇒1 0 0 0 0 0
l⇒1 0 0 0 0 0
x-OR
0 0 0 0 0Þ0
m=0
Print;
i ⇒ 32
j ⇒ 32
k ⇒ 32
l ⇒ 32
m⇒0
Android App | iOS App | PW Website
https://qbg-admin.penpencil.co/finalize-question-paper/preview-pdf 5/5