当前位置:网站首页>C语言-入门-基础-语法-数据类型(四)
C语言-入门-基础-语法-数据类型(四)
2022-07-04 08:47:00 【胡安民】
什么是数据?
生活中无时无刻都在跟数据打交道
- 例如:人的体重、身高、收入、性别等数据等
- 在我们使用计算机的过程中,也会接触到各种各样的数据
- 例如: 文档数据、图片数据、视频数据等
数据分类
静态的数据
- 静态数据是指一些永久性的数据,一般存储在硬盘中。硬盘的存储空间一般都比较大,现在普通计算机的硬盘都有500G左右,因此硬盘中可以存放一些比较大的文件
- 存储的时长:计算机关闭之后再开启,这些数据依旧还在,只要你不主动删掉或者硬盘没坏,这些数据永远都在
- 哪些是静态数据:静态数据一般是以文件的形式存储在硬盘上,比如文档、照片、视频等。
动态的数据
- 动态数据指在程序运行过程中,动态产生的临时数据,一般存储在内存中。内存的存储空间一般都比较小,现在普通计算机的内存只有8G左右,因此要谨慎使用内存,不要占用太多的内
存空间- 存储的时长:计算机关闭之后,这些临时数据就会被清除
- 哪些是动态数据:当运行某个程序(软件)时,整个程序就会被加载到内存中,在程序运行过程中,会产生各种各样的临时数据,这些临时数据都是存储在内存中的。当程序停止运行或者计算机被强制关闭时,这个程序产生的所有临时数据都会被清除。
既然硬盘的存储空间这么大,为何不把所有的应用程序加载到硬盘中去执行呢?
- 主要原因就是内存的访问速度比硬盘快N倍
- 静态数据和动态数据的相互转换 ,也就是从磁盘加载到内存
- 动态数据和静态数据的相互转换,也就是从内存保存到磁盘
作为程序员, 我们最关心的是内存中的动态数据,因为我们写的程序就是在内存中运行的, 程序在运行过程中会产生各种各样的临时数据,为了方便数据的运算和操作, C语言对这些数据进行了分类, 提供了丰富的数据类型
数据类型介绍
C语言的数据类型有:基本类型、空类型、构造类型和指针类型。其中构造类型中包括共用体、数组、结构体三种类型。基本类型中还包括整型、浮点型、字符型和枚举型四种类型。

在C语言中,承载一系列信息的数字或中字符都属于数据类型,计算机不能直接识别不同的类型,所以在使用变量时需要在声明语句中指定其数据类型。C语言的数据类型,通俗的理解就是将不同的物品放在不同的盒子中,比如小数存放在浮点型、整数存放在整型、字符存放在字符型等等,在编写C语言时需要根据存放数据的不同,定义不同的类型变量。
例如:int整型一般是分配4个字节存储空间,double双精度浮点型分配8个字节的存储空间;变量的数据类型同时决定着该变量能取哪些值和进行哪些运算。如整数类型只能取整数值,小数类型可以表示小数,整数和小数可以进行加减乘除数学运算。
基本数据类型
C语言种最基本数据类型是算术类型,包括整数类型和浮点数类型。字符类型、枚举类型本质也是整数类型;整数类型细分有符号和无符号整数、长整数和短整数;不同整数类型区别是存储长度不一样、取值范围大小不一样;浮点数类型比较简单,都是有符号的,分为单精度和双精度浮点数。
整数类型以及声明关键字包括:
- 字符类型:
char(至于是有符号或无符号由编译器实现自定义) - 有符号字符类型:
signed char - 无符号字符类型:
unsigned char - 有符号短整型:
short,signed short,short int,signed short int - 无符号短整型:
unsigned short,unsigned short int - 有符号整型:
int,signed,signed int - 无符号整型:
unsigned,unsigned int - 有符号长整型:
long,signed long,long int,signed long int - 无符号长整型:
unsigned long,unsigned long int
浮点类型声明包括:
- 单精度浮点型:
float - 双精度浮点型:
double - 长双精度浮点型:
long double
常用基本数据类型大小
char 1字节,int 4字节, long 8字节,float 4字节,double 8字节;每种类型存储空间大小,所占字节数,和计算机位数有关,不同机器数据类型大小不一样,可以通过 sizeof() 关键字进行每种类型大小的计算,确定存储空间和取值范围。
获取当前机器的变量大小
#include<stdio.h>
int main()
{
printf("int = %d\n",sizeof(int));
printf("short = %d\n",sizeof(short));
printf("long int = %d\n",sizeof(long int));
printf("long long int = %d\n",sizeof(long long int));
printf("char = %d\n",sizeof(char));
printf("_Bool = %d\n",sizeof(_Bool));
printf("float = %d\n",sizeof(float));
printf("double = %d\n",sizeof(double));
printf("long double = %d\n",sizeof(long double));
}

32位编译器和64位编译器区别
32位编译器
- char :1个字节
- char*(即指针变量): 4个字节(32位的寻址空间是2^32, 即32个bit,也就是4个字节)
- short int : 2个字节
- int: 4个字节
- unsigned int : 4个字节
- float: 4个字节
- double: 8个字节
- long: 4个字节
- long long: 8个字节
- unsigned long: 4个字节
64位编译器 (目前基本都是64的了)
- char :1个字节
- char*(即指针变量): 8个字节
- short int : 2个字节
- int: 4个字节
- unsigned int : 4个字节
- float: 4个字节
- double: 8个字节
- long: 8个字节
- long long: 8个字节
- unsigned long: 8个字节


边栏推荐
- NewH3C——ACL
- Horizon sunrise X3 PI (I) first boot details
- Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
- @Role of requestparam annotation
- How to pass custom object via intent in kotlin
- 没有Kubernetes怎么玩Dapr?
- Newh3c - routing protocol (RIP, OSPF)
- Awk from entry to earth (7) conditional statements
- C语言-入门-基础-语法-[标识符,关键字,分号,空格,注释,输入和输出](三)
- Group programming ladder race - exercise set l2-002 linked list de duplication
猜你喜欢

The second session of the question swiping and punching activity -- solving the switching problem with recursion as the background (I)

Démarrage des microservices: passerelle

Redis 哨兵机制

System disk expansion in virtual machine

Ehrlich sieve + Euler sieve + interval sieve
](/img/89/0f5f4ba07c637b09abe873016cba2d.png)
C语言-入门-基础-语法-[标识符,关键字,分号,空格,注释,输入和输出](三)
![[error record] no matching function for call to 'cacheflush' cacheflush();)](/img/79/c00f9c835606b2dce1d342ec368d24.jpg)
[error record] no matching function for call to 'cacheflush' cacheflush();)

地平线 旭日X3 PI (一)首次开机细节

Educational Codeforces Round 115 (Rated for Div. 2)

根据数字显示中文汉字
随机推荐
How can we make a monthly income of more than 10000? We media people with low income come and have a look
awk从入门到入土(8)数组
manjaro安装微信
学习Nuxt.js
Mouse over to change the transparency of web page image
Awk from entry to earth (12) awk can also write scripts to replace the shell
[CV] Wu Enda machine learning course notes | Chapter 9
awk从入门到入土(4)用户自定义变量
What if the wireless network connection of the laptop is unavailable
Developers really review CSDN question and answer function, and there are many improvements~
团体程序设计天梯赛-练习集 L2-002 链表去重
Conversion of yolov5 XML dataset to VOC dataset
Codeforces Round #793 (Div. 2)(A-D)
09 softmax regression + loss function
微服務入門:Gateway網關
Guanghetong's high-performance 4g/5g wireless module solution comprehensively promotes an efficient and low-carbon smart grid
awk从入门到入土(18)gawk线上手册
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
[BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
埃氏筛+欧拉筛+区间筛