Data Types of C Language Kingdom Adventure

Kingdom Adventures Series

Article Directory (1)


Table of contents

1. What is the relationship between writing programs and data types?

2. What data types are there in the C language?

1. Introduction to data types

2. Why do floating-point numbers describe decimals?

3. Which of the numbers in the program are integers and which are characters?

summary:

2. What are the sizes of the data types?

1. Before calculating the size, you must first know what the C language uses to calculate

 2, Now print the size of each data type

 3. Common units and introductions in computers

1. What is a bit?

2, Conversion between units

3. Why do we have so many types of integers?

4. Why are the calculation sizes of int and long both 4?

Summarize


foreword

Adventures in the Kingdom of C Language is the adventure journey of the C language we learned, from a small boy to a big boss. In this chapter, we will take down the data type.


1. Data type

1. What is the relationship between writing programs and data types?

It is to solve some problems in life. If you want to solve the problem, you must describe the problem.

For example, if we want to write an online shopping mall, do you want to describe the shopping process, then do you want to describe the product? Do you want to describe the product: name, pricing, current preferential policies, etc.

If you want to describe the price, do you need variables, values, and numbers?

You write programs to solve problems in life. If you want to solve problems in life, you must be able to describe the problems in life. When describing various objects, you need some data, such as prices. , height etc.

To be able to describe these problems in C language, there must be data types. 

2. What data types are there in the C language?

1. Introduction to data types

 short, int, long, long long are all integers, which are used to describe the integers we use.

char is the character data type, what is a character, that is, what we type on the keyboard are all characters:

Such as: &*) (adhbsjdfh , these letters are all characters, our name is composed of characters described by the character type, and a single character can be stored in the char type.

float (lower precision), double (higher precision), and the floating-point type describes decimals .

2. Why do floating-point numbers describe decimals?

when using scientific notation. The decimal point can be moved so it is called a floating point number

123.45

12.345*10^1

1.2345*10^2

3. Which of the numbers in the program are integers and which are characters?

Put the number into the integer type

20;

2;

Characters are placed in the char type

‘2’

‘0’

summary:

These types are equivalent to molds one by one. When we make mooncakes, a large mold can make a big mooncake, and a small mold can make a small mooncake.

2. What are the sizes of the data types?

1. Before calculating the size, you must first know what the C language uses to calculate

Directly upload the code, there is an introduction in the code, and then our running results.

int main()
{
    //%d -- 十进制的形式打印整数
	sizeof(char);
	//c语言里面的一个操作符叫做sizeof()
	//sizeof()里面放一个cahr就能计算cahr的大小
	//我们要想打印出来就
	printf("%d\n", 100);//打印100的时候我们就在这里写一个一百就行
	//%d的意思是我要打印一个整型,%d是一个占位符,打印的时候后面的100会将把%d替换掉
	//这是printf()的功能
    return 0;
}
 
 

 2, Now print the size of each data type

int main()
{
    printf("%d\n", sizeof(char));//我们使用sizeof()计算出模具的大小,然后用%d的形式打印出来
	printf("%d\n", sizeof(short )); 
	printf("%d\n", sizeof(int)); 
	printf("%d\n", sizeof(long)); 
	printf("%d\n", sizeof(long long));
	printf("%d\n", sizeof(float));
	printf("%d\n", sizeof(double));
   	return 0;//sizeof()计算的结果的单位是字节

}

The operation diagram of the calculation result is as follows

 3. Common units and introductions in computers

1. What is a bit?

bit - bits         

Bit is the smallest unit in our computer

What is this bit? There are only 1/0 in binary, and a small space is needed to store 1 in binary. The size of this space is called bit .

2, Conversion between units

byte - byte 1byte = 8bit  

KB -                         1KB = 1024byte

MB                           1MB = 1024KB

GB                           1GB = 1024MB

TB                            1TB = 1024GB

PB                            1PB = 1024TB

 .....                            .....

3. Why do we have so many types of integers?

Because the space is large, the data to be stored is larger, and the space is small, the things to be stored are smaller. The purpose of providing so many types is to enrich our choices. We can choose the one that suits us, which can make our computer memory space higher utilization

4. Why are the calculation sizes of int and long both 4?

long can be big or wait for int

The C language standard states:

sizeof(long long)>=sizeof(long)>=sizeof(int)>=sizeof(short)>=sizeof(char)

Summarize

The above is what I want to talk about today. This article only briefly introduces the data types in C language. This is a small hurdle on our way of learning. Congratulations for overcoming it.

Guess you like

Origin blog.csdn.net/weixin_73466540/article/details/131365349