You are on page 1of 27

SELECTION STRUCTURES

CLASS AGENDA
• Attendance
• Midterm Departmental Exam
 Wednesday, October 26, 2022 (face-to-face)
 Time: 8:30 AM – 10:00 AM
 Room: A2401

• Review/Practice: Midterm Departmental Exam


REVIEW
MIDTERM DEPARTMENTAL EXAM

C Expressions
Selection Structures

3
1) Which of the following is the
complement of less than (<)?

a) >
b) >=
c) < =
1) Which of the following is the
complement of less than (<)?

a) >
b) >=
c) < =
Comparative
Operator
Complements
2) If a variable, x, contains the
value 3, the value of the
expression x-- is 2?

a) True
b) False
2) If a variable, x, contains the
value 3, the value of the
expression x-- is 2?

a) True
b) False
3) Given the following code, what
is printed?

int num = 10;


printf("%d %d", num, num++);

9
3) Given the following code, what
is printed?

int num = 10;


printf("%d %d", num, num++);

Answer: 11 10
10
4) Given: x = 15 y = 10 z=5

What is the value of the expression


x*2+y/3-z*y

11
4) Given: x = 15 y = 10 z=5

What is the value of the expression


x*2+y/3-z*y

Answer: -17
12
5) Given: x = 15 y = 10 z = 5

What is the value of the expression


--x * (5 + y) / 2 - z++

13
5) Given: x = 15 y = 10 z = 5

What is the value of the expression


--x * (5 + y) / 2 - z++

Answer: 100
14
6) What is the output of the code below?
int a=1;
if (a > 0)
printf("True");
if (a == 2)
printf("False")
else
printf("Invalid");
15
6) What is the output of the code below?
int a=1;
if (a > 0)
printf("True");
if (a == 2) Answer: error
printf("False") ;
else
printf("Invalid");
16
7) What is the output of the code below?
int a=1;
if (a > 0) {
printf("True");
}
else {
printf("False");
}
printf("Invalid"); 17
7) What is the output of the code below?
int a=1;
if (a > 0) {
printf("True");
} Answer:
else { TrueInvalid
printf("False");
}
printf("Invalid"); 18
8) What is the output of the code below?
int x=3;
switch(x)
case 1: printf("%d", x);
case 2: printf("%d", --x);
default: printf("%d", x++);

19
8) What is the output of the code below?
int x=3;
switch(x)
{
case 1: printf("%d", x);
case 2: printf("%d", --x);
default: printf("%d", x++);
}

Answer: error
20
9) What is the output of the code below?
char initial='a';
switch(initial)
{
case 'A':
case 'a':
printf("True");
default:
printf("False");
} 21
9) What is the output of the code below?
char initial='a';
switch(initial)
{ Answer:
case 'A':
case 'a':
TrueFalse
printf("True");
default:
printf("False");
} 22
10) --a is a postfix
expression.
A) True
B) False

23
10) --a is a postfix
expression.
A) True
B) False

24
Program Tracing
(by pair)

25
Practice
(by pair)

Midterm Departmental
Exam – Answer Sheet
26
Good luck,
students!

27

You might also like