当前位置:网站首页>C language - Introduction - Foundation - syntax - data type (4)
C language - Introduction - Foundation - syntax - data type (4)
2022-07-04 08:49:00 【Hu Anmin】
What is data ?
Dealing with data all the time in life
- for example : People's weight 、 height 、 income 、 Gender and other data
- In the process of using computers , Will also be exposed to a variety of data
- for example : Document data 、 Picture data 、 Video data, etc
data classification
Static data
- Static data refers to some permanent data , It's usually stored on a hard disk . The storage space of hard disk is generally large , Now the hard disk of ordinary computer has 500G about , Therefore, some large files can be stored in the hard disk
- The length of storage : Turn on the computer after it is turned off , The data is still there , As long as you don't take the initiative to delete or the hard disk is not broken , The data will always be
- Which are static data : Static data is usually stored on the hard disk in the form of files , Like documents 、 Photo 、 Video etc. .
Dynamic data
- Dynamic data refers to the process of running a program , Temporary data generated dynamically , Generally stored in memory . The memory space is generally small , Now the memory of ordinary computer is only 8G about , So use memory with caution , Don't occupy too much space
Storage space- The length of storage : After the computer is turned off , These temporary data will be cleared
- Which are dynamic data : When running a program ( Software ) when , The whole program will be loaded into memory , While the program is running , All kinds of temporary data are generated , These temporary data are stored in memory . When a program stops running or the computer is forced to shut down , All temporary data generated by this program will be cleared .
Since the hard disk has so much storage space , Why not load all the applications into the hard disk to execute ?
- The main reason is that the access speed of memory is faster than that of hard disk N times
- Conversion between static data and dynamic data , That is, load from disk to memory
- Conversion between dynamic data and static data , That is, save from memory to disk
As a programmer , What we care about most is the dynamic data in memory , Because the program we write runs in memory , All kinds of temporary data will be generated during the operation of the program , In order to facilitate the calculation and operation of data , C Language classifies these data , Provides a wealth of data types
Data type introduction
C The data types of languages are : Basic types 、 Empty type 、 Construct type and pointer type . The construction type includes the common body 、 Array 、 There are three types of structures . Basic types also include integers 、 floating-point 、 There are four types of characters and enumerations .
stay C In language , Numbers or Chinese characters that carry a series of information are data types , Computers cannot directly recognize different types , Therefore, when using a variable, you need to specify its data type in the declaration statement .C The data type of the language , Popular understanding is to put different items in different boxes , For example, decimals are stored in floating point 、 Integers are stored in integer 、 Characters are stored in character type and so on , Writing C The language needs to be different according to the stored data , Define different types of variables .
for example :int Integers are generally allocated 4 Bytes of storage space ,double Double precision floating-point allocation 8 Bytes of storage space ; The data type of a variable also determines what values the variable can take and what operations it can perform . For example, integer type can only be rounded , Decimal type can represent decimal , Integers and decimals can be added, subtracted, multiplied and divided .
Basic data type
C The most basic data type of a language is arithmetic , Including integer type and floating point number type . Character type 、 Enumeration types are also integer types in nature ; Integer type subdivides signed and unsigned integers 、 Long and short integers ; The difference between different integer types is that the storage length is different 、 The value range is different ; Floating point number type is relatively simple , It's all symbolic , It is divided into single precision and double precision floating-point numbers .
Integer types and declaration keywords include :
- Character type :
char
( Whether it is signed or unsigned is customized by the compiler ) - Signed character type :
signed char
- The unsigned character type :
unsigned char
- Signed short integers :
short
,signed short
,short int
,signed short int
- Unsigned short :
unsigned short
,unsigned short int
- signed int :
int
,signed
,signed int
- Unsigned integer :
unsigned
,unsigned int
- Signed long integer :
long
,signed long
,long int
,signed long int
- Unsigned long :
unsigned long
,unsigned long int
Floating point type declarations include :
- Single precision floating point :
float
- Double precision floating point :
double
- Long double precision floating point :
long double
Common basic data type size
char 1 byte ,int 4 byte , long 8 byte ,float 4 byte ,double 8 byte ;
Storage space size of each type , Number of bytes taken , It is related to the number of digits in the computer , Different machine data types have different sizes , Can pass sizeof() Keyword to calculate the size of each type , Determine the storage space and value range .
Get the variable size of the current machine
#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 Bit compiler and 64 Bit compiler differences
32 Bit compiler
- char :1 Bytes
- char*( That is, pointer variable ): 4 Bytes (32 The addressing space of bits is 2^32, namely 32 individual bit, That is to say 4 Bytes )
- short int : 2 Bytes
- int: 4 Bytes
- unsigned int : 4 Bytes
- float: 4 Bytes
- double: 8 Bytes
- long: 4 Bytes
- long long: 8 Bytes
- unsigned long: 4 Bytes
64 Bit compiler ( At present, they are basically 64 Of course. )
- char :1 Bytes
- char*( That is, pointer variable ): 8 Bytes
- short int : 2 Bytes
- int: 4 Bytes
- unsigned int : 4 Bytes
- float: 4 Bytes
- double: 8 Bytes
- long: 8 Bytes
- long long: 8 Bytes
- unsigned long: 8 Bytes
边栏推荐
- SQL statement view SQL Server 2005 version number
- Newh3c - routing protocol (RIP, OSPF)
- 1211 or chicken and rabbit in the same cage
- The basic syntax of mermaid in typera
- swatch
- deno debugger
- Codeforces Round #750 (Div. 2)(A,B,C,D,F1)
- Démarrage des microservices: passerelle
- Awk from entry to earth (15) awk executes external commands
- System disk expansion in virtual machine
猜你喜欢
The basic syntax of mermaid in typera
Relationship and operation of random events
Turn: excellent managers focus not on mistakes, but on advantages
随机事件的关系与运算
User login function: simple but difficult
Collections in Scala
C语言-入门-基础-语法-[标识符,关键字,分号,空格,注释,输入和输出](三)
High order phase difference such as smear caused by myopic surgery
广和通高性能4G/5G无线模组解决方案全面推动高效、低碳智能电网
AcWing 244. Enigmatic cow (tree array + binary search)
随机推荐
How college students choose suitable computers
The basic syntax of mermaid in typera
C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,Gauss-Jordan消去法,源代码
From scratch, use Jenkins to build and publish pipeline pipeline project
地平线 旭日X3 PI (一)首次开机细节
awk从入门到入土(9)循环语句
DM8 tablespace backup and recovery
Collections in Scala
上周热点回顾(6.27-7.3)
Talk about single case mode
C, Numerical Recipes in C, solution of linear algebraic equations, Gauss Jordan elimination method, source code
【无标题】转发最小二乘法
埃氏筛+欧拉筛+区间筛
A subclass must use the super keyword to call the methods of its parent class
如何通过antd的upload控件,将图片以文件流的形式发送给服务器
How to choose solid state hard disk and mechanical hard disk in computer
Ehrlich sieve + Euler sieve + interval sieve
没有Kubernetes怎么玩Dapr?
C#实现一个万物皆可排序的队列
DM8 database recovery based on point in time