Alex

@import “../../css/font-awesome-4.7.0/css/font-awesome.css” @import “../../css/theme/solarized.css” @import “../../css/logo.css” @import “../../css/font.css” @import “../../css/color.css” @import “../../css/margin.css” @import “../../css/table.css” @import “../../css/main.css” @import “../../plugin/zoom/zoom.js” @import “../../plugin/customcontrols/plugin.js” @import “../../plugin/customcontrols/style.css” @import “../../plugin/chalkboard/plugin.js” @import “../../plugin/chalkboard/style.css” @import “../../plugin/menu/menu.js” @import “../../js/anychart/anychart-core.min.js” @import “../../js/anychart/anychart-venn.min.js” @import “../../js/anychart/pastel.min.js” @import “../../js/anychart/venn-ml.js”

C语言程序设计基础


数据类型

计算机学院    杨已彪

yangyibiao@nju.edu.cn



Review

Functions

Function Definition

Function Declaration

Arrays as Parameters

Pass by Value



Overview

</br> </br> </br>

(Basic) Data Types



Two Major Reasons




Architectures May Vary



Finite vs. Infinite



Object



w:1250



Object Types  Function Types



Data Types


The **type** of a variable determines







int    char    bool  (_Bool)  double


[ ]



Integral Types (size.c)


w:1000



Integral Types


w:1150



Integral Types (int-limits.c)




Integral Types (exact-width.c)


int8_t   int16_t   int32_t   int64_t  

w:1000

stdint.h



Signed and Unsigned (unsigned.c)




Be careful when MIXING signed and unsigned types.




Signed and Unsigned (sizet.c)




w:1200



typedef



typedef unsigned __int64 size_t


#define _ _int64 long long


typedef long long time_t


char (char.c)



Use char only for representing characters.


Do NOT assume signed char or unsigned char.


Overflow

(unsigned-wrap.c   for-unsigned.c   unsigned-wrap-fix.c)



无符号整数运算中没有溢出, 取而代之的是**回绕 (wrap)**现象


Overflow

(signed-overflow-fix.c)



有符号整数运算中发生溢出, 程序的行为是**未定义的**


Implicit Conversion

(implicit-conversion.c)


Be careful about narrowing conversions!!!


Implicit Conversion


Integer promotions (integer-promotion.c)


Integer conversion rank (Section 7.4.3)


Usual arithmetic conversions (Section 7.4.1)


Explicit Conversion

(explicit-conversion.c)



(type) expression


Floating-point Numbers

(float-limits.c)



w:300

"Floating-point Arithmetic is Hard."

(Section 23.1 float.h)


"Many applications don't need floating-point arithmetic at all."

w:260

Use math.h (Section 23.3) whenever possible.


bg w:1000


IEEE 754

w:1200 $24 \; (\approx 6) \qquad\qquad 53 \; (\approx 16)$

w:1200


bg w:1100


w:1100





What is a subnormal floating point number? @ stackoverflow





implicit-conversion.c


sum-product.c   loop.c   compare.c


w:450


w:460    w:450


bg w:600