ASCII码、可移植类型、复数虚数、sizeof函数——the fifth——2022.12.26

%c按照ASCII码转换字符

 

 例如:


 

#include <stdio.h>

int main(void) {
char ch;
printf("Please enter a character.\n");
scanf("%c", &ch);
printf("The code for %c is %d.\n", ch, ch);

return 0;
}


 

输出结果:

Please enter a character.

C

The code for C is 67.

 

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

精确宽度整数类型(exact-width integer type)——int32_t

最小宽度类型(minimum width type)——int_least8_t

最快最小宽度类型(fastest minimum width type)——int_fast8_t

最大整数类型——intmax_t

 

复数与虚数

C语言有三种复数类型:float_Complex、double_Complex 和 long double_Complex

例如,float_Complex类型的变量应包含两个float类型的值,分别表示复数的实部和虚数。

C语言有三种虚数类型:float_Imaginary、double_Imaginary、long_Imaginary

 

利用sizeof知道当前系统的指定类型大小


 

int main(void) {
printf("Type int has a size of %zd bytes.\n", sizeof(int));
printf("Type char has a size of %zd bytes.\n", sizeof(char));
printf("Type long has a size of %zd bytes.\n", sizeof(long));
printf("Type short has a size of %zd bytes.\n", sizeof(short));
printf("Type long long has a size of %zd bytes.\n", sizeof(long long));
printf("Type double has a size of %zd bytes.\n", sizeof(double));
printf("Type long double has a size of %zd bytes.\n", sizeof(long double));


 

输出:

Type int has a size of 4 bytes.

Type char has a size of 1 bytes.

Type long has a size of 4 bytes.

Type short has a size of 2 bytes.

Type long long has a size of 8 bytes.

Type double has a size of 8 bytes.

Type long double has a size of 16 bytes.

 

posted @ 2022-12-27 17:20  江理第一深情  阅读(69)  评论(0)    收藏  举报