Skip to content

Commit

Permalink
added ex4.25~4.27
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Sep 26, 2014
1 parent 399a625 commit f326216
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ch04/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,25 @@ finalgrade = ((grade > 90) ? "high pass" : (grade < 60)) ? "fail" : "pass";
```
if `grade > 90`, first conditional operator's result is `high pass`. so the finalgrade is always fail.
It's contradictory obviously.

##Exercise 4.25
>What is the value of ~'q' << 6 on a machine with 32-bit ints and 8 bit chars, that uses Latin-1 character set in which 'q' has the bit pattern 01110001?
the value is `-7296.`

~01110001 == 10001110(142), But `char` is -128~127, so it would be overflow. the result is `-114`, then, -114 << 6 == -114 * 2^6 = `-7296`.

##Exercise 4.26
>In our grading example in this section, what would happen if we used unsigned int as the type for quiz1?
no different in most situation. `unsigned int` have the same size as `unsigned long` on most machine. But the second one could make sure that it have **at least 32 bits** on any machine.

##Exercise 4.27
>What is the result of each of these expressions?
```cpp
unsigned long ul1 = 3, ul2 = 7;
ul1 & ul2 // == 3
ul1 | ul2 // == 7
ul1 && ul2 // == true
ul1 || ul2 // == ture
```

0 comments on commit f326216

Please sign in to comment.