c 打印html数据类型,C 数据类型

了解C - C数据类型

下表总结了变量类型。类型典型字节数典型的值范围char1-128至+127 或 0至+255

unsigned char10至+255

short2-32,768至+32,767

unsigned short20至+65,535

int2 或 4-32,768至+32,767 或 -2,147,438,648至+2,147,438,647

unsigned int40至+65,535 或 0至+4,294,967,295

long4-2,147,438,648至+2,147,438,647

unsigned long40至+4,294,967,295

long long8-9,223,372,036,854,775,808至+9,223,372,036,854,775,807

unsigned long long80至+18,446,744,073,709,551,615

float4+/- 3.4E +/- 38(6位数)

double8+/- 1.7E +/- 308(15位数)

long double12+/- 1.2E +/- 4932(19位数)

局限性

一些符号常量来自limit.h符号常量表示CHAR_BITchar中的位数

CHAR_MAX最大char值

CHAR_MIN最小char值

SCHAR_MAX最大带符号char值

SCHAR_MIN最小带符号char值

UCHAR_MAX最大无符号char值

SHRT_MAX最大short值

SHRT_MIN最小short值

USHRT_MAX最大无符号short值

INT_MAX最大int值

INT_MIN最小int值

UINT_MAX最大无符号int值

LONG_MAX最大long值

LONG_MIN最小long值

ULONG_MAX最大无符号long值

LLONG_MAX最大long long值

LLONG_MIN最小long long值

ULLONG_MAX最大无符号long long值

使用从limit.h和float定义的常量。

#include

#include // integer limits #include // floating-point limits int main(void)

{

printf("Some number limits for this system:\n");

printf("Biggest int: %d\n", INT_MAX);

printf("Smallest long long: %lld\n", LLONG_MIN);

printf("One byte = %d bits on this system.\n", CHAR_BIT);

printf("Largest double: %e\n", DBL_MAX);

printf("Smallest normal float: %e\n", FLT_MIN);

printf("float precision = %d digits\n", FLT_DIG);

printf("float epsilon = %e\n", FLT_EPSILON);

return 0;

}

上面的代码生成以下结果。

85a139b7b477d30275792a4c1313bded.png

例子

将2英寻转换成英尺

#include

int main(void)

{

int feet, fathoms;

fathoms = 2;

feet = 6 * fathoms;

printf("There are %d feet in %d fathoms!\n", feet, fathoms);

printf("Yes, I said %d feet!\n", 6 * fathoms);

return 0;

}

上面的代码生成以下结果。

83ebb730a18d8f509e6243d69c8f96f5.png

例2

以下代码显示了如何从命令行读取int值。

#include

int main(void)

{

int dogs;

printf("How many dogs do you have?\n");

scanf("%d", &dogs);

printf("So you have %d dog(s)!\n", dogs);

return 0;

}

上面的代码生成以下结果。

971a1871c775e51f67dd3a9f9f3c71c8.png

例3

以下代码显示如何使用整数类型的可移植名称。

#include

#include // supports portable typesint main(void)

{

int32_t me32; // me32 a 32-bit signed variable

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("me32 = %" PRId32 "\n", me32);

return 0;

}

上面的代码生成以下结果。

606a9f47dec5675f6b2c41ce63d7223a.png

例4

下面的代码显示了如何以十进制,八进制和十六进制打印100。

#include

int main(void)

{

int x = 100;

printf("dec = %d; octal = %o; hex = %x\n", x, x, x);

printf("dec = %d; octal = %#o; hex = %#x\n", x, x, x);

return 0;

}

上面的代码生成以下结果。

193a2d5af047200f2196c5c10c0d6d84.png

例5

下面的代码声明和使用各种int类型。

#include

int main(void)

{

unsigned int un = 3000000000; /* system with 32-bit int */

short end = 200; /* and 16-bit short */

long big = 65537;

long long verybig = 12345678908642;

printf("un = %u and not %d\n", un, un);

printf("end = %hd and %d\n", end, end);

printf("big = %ld and not %hd\n", big, big);

printf("verybig= %lld and not %ld\n", verybig, verybig);

return 0;

}

上面的代码生成以下结果。

91f85671c8e45d05cc5a6a45a3150564.png

例6

下面的代码以两种方式显示浮点值。

#include

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);

// next line requires C99 or later compliance printf("And it"s %a in hexadecimal, powers 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;

}

上面的代码生成以下结果。

35a319f967613aa4ffa725ccb4e8d782.png

例7

以下代码显示如果值超过最大int大小会发生什么。

#include

int main(void)

{

int i = 2147483647;

unsigned int j = 4294967295;

printf("%d %d %d\n", i, i+1, i+2);

printf("%u %u %u\n", j, j+1, j+2);

return 0;

}

上面的代码生成以下结果。

7403fbec8b357ab7beb01142af81cd3b.png

例8

以下代码打印出类型大小。

#include

int main(void)

{

/* c99 provides a %zd specifier for sizes */

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 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));

return 0;

}

上面的代码生成以下结果。

ddc5ed2660661e36551407a4f83ce37e.png

例9

#include

#include

#include

#include

#include

#include

int main(void)

{

printf("PTRDIFF_MIN = %td\n", PTRDIFF_MIN);

printf("PTRDIFF_MAX = %+td\n", PTRDIFF_MAX);

printf("SIZE_MAX = %zu\n", SIZE_MAX);

printf("SIG_ATOMIC_MIN = %+jd\n",(intmax_t)SIG_ATOMIC_MIN);

printf("SIG_ATOMIC_MAX = %+jd\n",(intmax_t)SIG_ATOMIC_MAX);

printf("WCHAR_MIN = %+jd\n",(intmax_t)WCHAR_MIN);

printf("WCHAR_MAX = %+jd\n",(intmax_t)WCHAR_MAX);

printf("WINT_MIN = %jd\n", (intmax_t)WINT_MIN);

printf("WINT_MAX = %jd\n", (intmax_t)WINT_MAX);

printf("CHAR_BIT = %d\n", CHAR_BIT);

printf("MB_LEN_MAX = %d\n", MB_LEN_MAX);

printf("\n");

printf("CHAR_MIN = %+d\n", CHAR_MIN);

printf("CHAR_MAX = %+d\n", CHAR_MAX);

printf("SCHAR_MIN = %+d\n", SCHAR_MIN);

printf("SCHAR_MAX = %+d\n", SCHAR_MAX);

printf("UCHAR_MAX = %u\n", UCHAR_MAX);

printf("\n");

printf("SHRT_MIN = %+d\n", SHRT_MIN);

printf("SHRT_MAX = %+d\n", SHRT_MAX);

printf("USHRT_MAX = %u\n", USHRT_MAX);

printf("\n");

printf("INT_MIN = %+d\n", INT_MIN);

printf("INT_MAX = %+d\n", INT_MAX);

printf("UINT_MAX = %u\n", UINT_MAX);

printf("\n");

printf("LONG_MIN = %+ld\n", LONG_MIN);

printf("LONG_MAX = %+ld\n", LONG_MAX);

printf("ULONG_MAX = %lu\n", ULONG_MAX);

printf("\n");

printf("LLONG_MIN = %+lld\n", LLONG_MIN);

printf("LLONG_MAX = %+lld\n", LLONG_MAX);

printf("ULLONG_MAX = %llu\n", ULLONG_MAX);

printf("\n");

printf("FLT_RADIX = %d\n", FLT_RADIX);

printf("DECIMAL_DIG = %d\n", DECIMAL_DIG);

printf("FLT_MIN = %e\n", FLT_MIN);

printf("FLT_MAX = %e\n", FLT_MAX);

printf("FLT_EPSILON = %e\n", FLT_EPSILON);

printf("FLT_DIG = %d\n", FLT_DIG);

printf("FLT_MANT_DIG = %d\n", FLT_MANT_DIG);

printf("FLT_MIN_EXP = %d\n", FLT_MIN_EXP);

printf("FLT_MIN_10_EXP = %d\n", FLT_MIN_10_EXP);

printf("FLT_MAX_EXP = %d\n", FLT_MAX_EXP);

printf("FLT_MAX_10_EXP = %d\n", FLT_MAX_10_EXP);

printf("FLT_ROUNDS = %d\n", FLT_ROUNDS);

printf("FLT_EVAL_METHOD = %d\n", FLT_EVAL_METHOD);

}

上面的代码生成以下结果。

f9a4e8e2c89cfc38932bb8e5678a1fdb.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值