C Primer Plus 读书笔记 · 16

#2019.9.8#C Primer Plus 读书笔记 · 16_第1张图片C Primer Plus 读书笔记 · 16_第2张图片

Examples Using Modifiers and Flags
(See some understandable examples from P188 to P 121, Listing 4.7 to Listing 4.10)
Using What You Just Learn

What Dose a Conversion Specification Convert?

Conversion specifications are really translation specifications.
(See Listing 4.11 on P122 for a sample program)
Mismatched Conversions
On certain system, 65200 represents -336 when interpreted as a signed int and represents 65200 when iterpreted as a unsigned int

A moral: Don’t expect a %u conversion to simply strip the sign from a number.

When you try to convert a value greater than 255 to a character in a printf() using %c, because a short int is 2 bytes and a char is 1 byte,
it looks at only 1 byte out of the 2 used to hold 336. This truncation amounts to(等同于) dividing the integer by 256 and keeping just the remainder. (More technically, youcan say that the numer is interprested modulo 256)
C Primer Plus 读书笔记 · 16_第3张图片
When we tryied printing an integer(65618) larger than the maximum short int(32767) allowed on our system, the computer againe dose its modulo thing that the printf() use only 2 bytes while 65618 is stored as a 4-byte int value. This corresponds to using the reminder after dividing by 65536. (A remainder between 32767 and 65536 would be printed as a negative number.)

(See Listing 4.2 on P124 for a sample which shows what will happend if you start mixing interger and float types)
The float is converted to double when used as arguementsvto printf().
Even the correct specifier can cause phony results if the printf() statement has mismathced elsewhere.

Passing Arguments
C Primer Plus 读书笔记 · 16_第4张图片

你可能感兴趣的:(C Primer Plus 读书笔记 · 16)