C语言学习笔记[第5天]2022.11.15

三、数据和C

4. C语言基本数据类型
4.2 其他整数类型
4.3 使用字符:char 类型

​ ■整数常量例子

类型十六进制八进制十进制
char\x41\101N.A.
int0x41010165
unsigned0x41u0101u65u
long0x41L0101L65L
unsigned long0x41UL0101UL65UL
long long0x41LL0101LL65LL
unsigned long long0x41ULL0101ULL65ULL

​ ■打印字符

/* charcode.c-显示字符的代码编号 */
#include <stdio.h>
int main(void)
{
    char ch;
    
    print("Please enter a character.\n");
    scanf("%C",&ch);
    print("The code for %c is %d.\n",ch,ch);
    
    return 0;
}
//Please enter a character.
//C
//The code for C is 67. 
4.4 _Bool类型

​ ■true和false

4.5 可移植类型:stdint.h和inttypes.h

​ ■精确宽度整数类型

​ ■最小宽度类型

/* altnames.c -- 可移植整数类型名 */
#include <stdio.h>
#include <inttypes.h> //支持可移植类型
int main(void)
{
    int32_t me32;	// me32是一个 32 位有符号整型变量
    
    me32 =45933945;
    printf("First, assume int32_t is int:");
    printf("me32 = %d\n", me32);
    printf("Next, let's not make any assumptions.\n");
    printf("Instead, use a \"macro\" from inttypes.h:");
    printf("me 32 = %" PRID32 "\N", me32);
    
  	return 0;
}

//First, assume int32_t is int: me32 = 45933945
//Next, let's not make any assumptions.
//Instead, use a "macro" from inttypes.h: me 32 = 45933945
4.6 float、double和long double

​ ■记数法示例

数字科学计数法指数计数法
10000000001.0×10⁹1.0e9
1230001.23×10⁵1.23e5
322.563.2256×10²3.2256e2
0.0000565.6×10⁻⁵5.6e-5

​ ■声明浮点型变量

float noah,jonah;
double troble;
float plank = 6.63e-34;
long double gnp;

​ ■浮点型常量

​ -1.56E+12

​ 2.87E-3

​ 3.14159

​ .2

​ 4e16

​ .8E-5100.

​ ■打印浮点值

/* showf_pt.c -- 以两种方式显示 float 类型的值 */
#include <stdio.h>
int main(void)
{
    float aboat = 32000.0;
    double abet = 2.14e9;
    long double dip =  5.32e-5;
    
    printf("%f can be written %e\n", aboat, aboat);
    // 下一行要求编译器支持C99或其中的相关特性
    printf("And it's %a in hexadecimalm, power of 2 notation\n", aboat);
    printf("%f can be written %e\n", abet, abet);
    printf("%Lf can be written %Le\n", dip, dip);
    
    return 0;
}

//32000.000000 can be written 32000e+04
//And it's 0x1.f4p+14 in hexadecimalm, power of 2 notation
//2140000000.000000 can be written 2.140000e+09
//0.000053 can be written 53320000e-05

​ ■浮点值的上溢和下溢

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值