Tải bản đầy đủ (.doc) (2 trang)

Bài tập Kỹ thuật vi xử lý - DTVT - BKDN (bài08)

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (51.54 KB, 2 trang )

Homework #8
Types, Operators, and Expression (Ch. 13) and Control Flow (Ch. 14)

In order to automate the grading process, please follow the exact instructions for each
questions and don’t use extra or unnecessary words.
1. (11 points) If a=6 and b=9 for each of the given expressions, what are the values of a and b
and the result of the expression after each statement is executed?
Expression

1
2
3
4
5
6
7
8
9
10
11

a
a
a
a
a
a
a
a
a
a


a

a

b

Result

| b
|| b
% b
%= b
= b
= b = 5
<<= b
== b
& b
&& b
&= b

2. (4 points) If i=2 and j=8 for each of the given statements, what are the values of i and j after
each statement is executed?

Expression

1
2
3
4


j
j
i
j

i

= ++i;
= i + 1;
+= 1;
= i += 1;

3. (2 points) What
the following code segment (True or False)?

j

output is generated by

int x = 3;
if (7 > x > 2)
printf ( "True" );
else
printf ( "False" );

4. (2 points) Does the following code cause an infinite loop? Why or why not? Hint: How does
overflow affect the condition statement? Use Code Composer Essentials to test this code.
int x = 1;
while (x > 0) x++;


BYU, ECEn/CS 124

Homework #8


5. (4 points) For the following statements:
int x , y;
switch (x)
{
case 0 : y = 1;
case 1 : y = 3; break;
default : y = 7; break;
} //end switch

a) What value will y have when x = 0?
b) What value will y have when x = 1?
6. (4 points) Suppose a program contains the two variables x and y.
a) First, write a routine (three lines) to exchange x and y using a temporary variable for
storage.

b) Rewrite this routine (three lines) to exchange x and y WITHOUT using a temporary
variable.

7. (3 points) What does this code print? Write all numbers printed in one line with a space
between prints.
for (i=0; i<10; i++) {
if (i > 5) break;
if (i > 1) continue;
printf(“%d ”, i);
}


Answer:

BYU, ECEn/CS 124

Homework #8



×