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

Control Flow Statements - DPP 01

The document contains programming exercises focused on decision control statements in C, specifically using 'if else' constructs. It includes multiple-choice questions (MCQs) and natural answer type (NAT) questions with corresponding outputs and explanations. Additionally, it provides an answer key and hints for solving the problems presented in the exercises.
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)
4 views5 pages

Control Flow Statements - DPP 01

The document contains programming exercises focused on decision control statements in C, specifically using 'if else' constructs. It includes multiple-choice questions (MCQs) and natural answer type (NAT) questions with corresponding outputs and explanations. Additionally, it provides an answer key and hints for solving the problems presented in the exercises.
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

1

Branch : CSE & IT Batch : Hinglish


Programming in C
Chapter : Control Flow Statements
Topic : Decision Control Statements (if else) DPP 01

[NAT] (b) GATE WALLAH


1. #include <stdio.h> (c) Compiler error
int main(void){ (d) Garbage value
int i = 2, j = 3, k = 4;
if (i < j ? 1 : 0) [NAT]
printf(“GATE”); 4. #include <stdio.h>
else void main( ){
printf(“Wallah2023”); int a;
return 0; a = printf(“GATE Wallah 2023”);
} if(a%4 = = 0)
The output of the program is ______. a = a + 5;
else
[MCQ] a = a – 5;
2. #include <stdio.h> printf(“%d”, a++);
void main( ){ }
int a, b, c, d; The value of a at the end of the program is ___.
a = 2; b = –1; c = 3; d = –4;
if(a = b – c – d) [NAT]
printf(“%d%d%d”, a++, b--, c++); 5. #include <stdio.h>
else void main( ){
printf(“%d%d%d”, c--, ++ a, ++b); int i, j, k;
} j = 4;
The output is ______. k = 0;
(a) 1 − 2 4 i = j < k ? k : j --;
(b) 3 1 0 if(j < i)
j = j + k – 1;
(c) 2 1 −3
if(j = = i)
(d) 3 3 0 j = j – i;
else
[MCQ] j = j + -- k,
3. #include <stdio.h> printf(“%d”, j + k – i);
int main(void){ }
int a = 3 > 2 ? 0 ? 0 : 1 : 5; The output is ___.
if(a = = a – 1)
printf(“GATE 2023”); [NAT]
else 6. Consider the following program:
printf(“GATE WALLAH”); #include<stdio.h>
return 0;
int main()
}
The output of the program is ______. {
(a) GATE 2023 int a=19, b=20;
2

if(a++<b--) printf("%d",a+++--b); }
else printf("%d", ++a+--b); The output string is:
return 0; (a) 0Hi22 (b) 0Hi20
(c) 0Bye0 (d) 0Hi00
}
The output is ____________. [MCQ]
8. #include<stdio.h>
[MCQ] void main()
7. #include<stdio.h> {
void main() int a=0, b=0;
{ a=(a=4)||(b=1);
int a=0; if(a&&b) printf("CProgramming");
printf("%d", a); else printf("PankajSharma");
if(a=2){ printf(“%d”,b);
printf("Hi"); }
printf("%d",a); The output is-
}else{ (a) CProgramming0
printf("Bye"); (b) CProgramming1
} (c) PankajSharma0
printf("%d", a); (d) PankajSharma1
3

Answer Key
1. (GATE) 6. (38)
2. (b) 7. (a)
3. (b) 8. (c)
4. (22)
5. (–4)
4

Hints and solutions

1. (GATE) printf returns the number of characters successfully


i<j?1:0 printed
In the above expression i value is less than j value, 16 % 4 = 0 → True
hence it will return 1. 
So, it will print GATE.
a =a +5

2. (c) a 16 21 22
a=–1–3+4 Hence the final value of a is 22.
a=0
a 2 0 5. (–4)
Assignment operator assigns and returns the value i j k
4 4 0 –1
b + + b: − 1 0 ,
3 2 1
a ++a: 0 1 , 3<4
j=3+0–1=2
c c−−: 3 2
2!=4
 j=j–1
Post decrement (It will print 3, then update to 2) =2–1
Output: 3 1 0 j=1
printed value = j + k – i
3. (b) =1–1–4
= –4
6. (38)
If(19<20)→ Condition is true. After the condition is
evaluated, a is incremented to 20 and b is decremented
to 19.
a=1 Now, printf("%d",a+++--b); is evaluated. b is
Assignment operator assigns the value and returns it decremented to 18. So, (20+18) i.e. 38 is printed. After
that, a is incremented to 21.
if (a = a – 1) Hence, output is 38.
1 4 2 43
0
 7. (a)
Condition: false
void main()
Output: GATE WALLAH {
int a=0;
4. (GATE Wallah 202321)
printf("%d", a); // 0 is printed
GATE Wallah 2023 if(a=2){//Assignment operator assigns and returns the
 assigned value; So 2 is assigned to a and 2 is returned.
a = 16 Any non-zero value is considered true.
printf("Hi");//”Hi” is printed
5

printf("%d",a);//Since a contains 2, 2 is printed. 8. (c)


}else{ a=0. b=0;
printf("Bye");
a=(a=4)||(b=1) //Assignment operator assigns and
}
returns the assigned value. Here, short-circuiting will
printf("%d", a); //Since a contains 2, 2 is printed
be applied. Since the logical operator is OR, if the
}
first part is true, second part is not evaluated at all.
Output: 0Hi22
Hence, b=0, a=1.
if(a && b)//The condition evaluates to 1 && 0 i.e. 0.
Hence, else part is evaluated.
Output: PankajSharma0

Any issue with DPP, please report by clicking here:- https://forms.gle/t2SzQVvQcs638c4r5


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