C Primer Plus 读书笔记 · 16

#2019.9.8#在这里插入图片描述在这里插入图片描述

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)
在这里插入图片描述
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
堆栈与传参

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值