通过本篇文章,我们的学习目的如下:
1、了解数据类型的基本分类
2、 熟练掌握基本数据类型
C 语言数据类型可以分为以下几种:
数组类型和结构类型,我们统称为聚合类型,函数类型指的是函数的返回值类型。在今天的这篇文章中,我们将重点讲解基本类型,其他的类型,我们会放在以后的章节在做详细的讲解。
整数类型:下表列出标准整数类型的存储大小和值范围
C语言程序示例(整数类型存储大小):
#include
#include
int main()
{
printf("Storage size for int : %d \n", sizeof(char));
printf("Storage size for int : %d \n", sizeof(unsigned char));
printf("Storage size for int : %d \n", sizeof(signed char));
printf("Storage size for int : %d \n", sizeof(int));
printf("Storage size for int : %d \n", sizeof(unsigned int));
printf("Storage size for int : %d \n", sizeof(short));
printf("Storage size for int : %d \n", sizeof(unsigned short));
printf("Storage size for int : %d \n", sizeof(long));
printf("Storage size for int : %d \n", sizeof(unsigned long));
return 0;
}
相关C语言技术点补充:
为了得到某个类型或某个变量在特定平台上的准确大小,您可以使用
sizeof
运算符。表达式
sizeof(type)
得到对象或类型的存储字节大小。
浮点类型:下表列出标准浮点类型的存储大小、值范围和精度
C语言程序示例(浮点类型)
#include
#include
int main()
{
printf("Storage size for float : %d \n", sizeof(float));
printf("Minimum float positive value: %E\n", FLT_MIN );
printf("Maximum float positive value: %E\n", FLT_MAX );
printf("Precision value: %d\n", FLT_DIG );
printf("Storage size for double : %d \n", sizeof(double));
printf("Minimum double positive value: %E\n", DBL_MIN );
printf("Maximum double positive value: %E\n", DBL_MAX );
printf("Precision value: %d\n", DBL_DIG );
printf("Storage size for long double : %d \n", sizeof(long double));
printf("Minimum long double positive value: %E\n", LDBL_MIN );
printf("Maximum long double positive value: %E\n", LDBL_MAX );
printf("Precision value: %d\n", LDBL_DIG );
return 0;
}
相关C语言技术点补充:
头文件 float.h 定义了宏,在程序中可以使用这些值和其他有关实数二进制表示的细节。
void 类型:void 类型指定没有可用的值,它通常用于以下三种情况。