Skip to Content
C语言核心技术(原书第2版)
book

C语言核心技术(原书第2版)

by Peter Prinz, Tony Crawford
August 2017
Intermediate to advanced
798 pages
17h 44m
Chinese
China Machine Press
Content preview from C语言核心技术(原书第2版)
类型转换
|
61
类型转换
型,其虚部等于
0
。
当复数被转换成不同的复数类型时,实部和虚部会各自根据实数浮点类型规则进行转
换:
#include <complex.h> //
定义宏,如虚数常量
I
double _Complex dz = 2;
float _Complex fz = dz + I;
在第一个初始化语句中,整数常量
2
被隐式地转换为
double_Complex
,并赋值给
dz
。
dz
的结果值是
2.0+ 0.0
×
I
。
在
fz
的初始化语句中,
double_Complex
类型
dz
值的两部分(在执行加法操作之后)都被
转换为
float
类型,所以
fz
的实部等于
2.0F
,虚部等于
1.0F
。
4.2 非算术类型的转换
指针以及数组、函数的名称也涉及某些隐式和显式的类型转换。结构和联合无法被转
换,虽然指向它们的指针可以来自于或被转换成其他指针类型。
4.2.1 数组和函数指示符
数组或函数的指示符(
designator
)是任何拥有数组或函数类型的表达式。在大多数情况
下,编译器隐式地将一个具有数组类型的表达式(例如数组名称),转换成指向数组第
一个元素的指针。只有在下面几种情况下,数组表达式才不会被转换为指针:
•
当数组是
sizeof
运算符的操作数时
•
当数组是地址运算符
&
的操作数时
•
当字符串字面量被用来初始化一个
char
、
wchar_t
、
char16_t
或
char32_t
数组时
下面的示例展示了将数组指示符隐式地转换成指针类型,并使用转换说明符
%p
来输出指
针值:
#include <stdio.h>
int ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

算法精讲视频课程:24篇系列讲座

算法精讲视频课程:24篇系列讲座

罗伯特·塞奇威克, 凯文·韦恩(Kevin Wayne)

Publisher Resources

ISBN: 9787111562207