当前位置:
文档之家› 北京大学计算概论课件2016lesson7v2 (1)
北京大学计算概论课件2016lesson7v2 (1)
Total, total represent different identifiers
5
C 语言的数据类型
• 整数、浮点数编码 • 整数、浮点数运算 • 字符类型 • 溢出与精度问题 • 变量、常量及数组的使用
6
Integer Data Types (continued)
7
7
Data types (integer type)
Examples of invalid C programmer-created names:
4ab7 calculate total While
Examples of valid user-created names:
_systemBuffer LJ113_10am
C is a case-sensitive language
Floating-Point Data Types (cont.)
• float literal is indicated by appending an f or F
• long double is created by appending an l or L
– 9.234 indicates a double literal – 9.234f indicates a float literal – 9.234L indicates a long double literal
Integer Data Types
— short or long
• int can have short or long modifier (usually write long rather than long int)
• short / long can modify the capacity of an int (sizes are hardware dependent)
Library Executable statements
programming is fun. press a key to continue...
10
11
12
Integer Data Types
— signed vs unsigned
• int or char can have signed or unsigned modifier (signed usually implicit)
第7讲 C语言 变量与表达式
Hu Junfeng 2016/10/12
1
— 熵(entropy)
• 编码系统的熵
扩展阅读: /wiki/Entropy
Binary entropy function
• 类型化 • C的类型 • 指针 • 函数
C语言概述
• real numbers with a decimal and/or exponent (1.5 or 2.67e-3)
• stored in floating point format (mantissa, exponent and sign bit)
• single precision uses float keyword • double precision uses double keyword • long modifier can be applied to double
Data type
short int int Unsigned short unsigned
size (bit)
range of values
16
-32K ~ 32K-1 (- 32768 ~ 32767)
32 -2G ~ 2G-1
16 64K -1 ~ 0
32 4G-1 ~ 0
8
8
• int i,j=0; • folat f1; • char ch;
printf(“Programming is fun!\n"); printf("I see!"); return 0; }
comments
Reserved words Standard routine Tokens: end of statement
4
Identifiers (continued)
• not used with char
Data types (integer type)
Data type
short int int Unsigned short unsigned
size (bit)
range of values
16
-32K ~ 32K-1 (- 32768 ~ 32767)
32 -2G ~ 2G-1
16ቤተ መጻሕፍቲ ባይዱ64K -1 ~ 0
32 4G-1 ~ 0
15
Character Data Type
• ASCII character set (A-Za-z0-9, etc.) • char is a single byte in size also used for
small integers
Floating Point Data Types
变量声明
General Structure of a C Program
/* My first program in C */
#include <stdio.h>
int main()
{
int i;
scanf(“%d”,&i);
printf(“fun + %d\n”,i);
return 0; }
Place holder
• char can be default signed or unsigned depending on compiler implementation; specify explicitly if important
• unsigned allows a bigger absolute number (e.g. 0 to 255 vs -128 to 127)
Identifiers(标识符)
Identifiers in C consist of three types:
Reserved words Standard identifiers Programmer-created identifiers
/* A first program in C */ #include <stdio.h> int main() {