Data structure-data type

Data structure and data type

1. Difference

data structure:

Data structure is the way a computer stores and organizes data. Data structure refers to a collection of data elements that have one or more specific relationships with each other. Under normal circumstances, a carefully selected data structure can bring higher operational or storage efficiency. Data structure is often related to efficient retrieval algorithms and indexing techniques.

Commonly used data structures: Array, Linked List, Hash, etc.

type of data:

The data type is the attribute of each data in the code, such as int, string, bool, double, etc.

In a general computer, int occupies 4 bytes, 32 bits, and the data range is -2147483648~ 2147483647 [-2 31 ~2 31 -1]

2. The use of data structure

In the development of computer science, data structures have also evolved. There are many data structures commonly used in programming, such as arrays.

For example:

//新建一个长度为3的数组并且初始化:0,1,2,他们三个初始值都是0。
int[] i = new int[3];
  • The array here is a structure of data.

3. The use of data types

The data type is the attribute of the data. If you can’t determine the attribute of the data in the code, you can’t control your own code, because all the different attributes of the data can achieve different effects, and there are many different things you can do. , The data type determines how the code will run.

For example:

//C#
	double d = 1.5d;
	int i = (int)d;
	//这里用到了类型转换,将d的类型由double转换为了int
	Console.WriteLine(d);
	Console.WriteLine(i + i);
	//这里的d将会输出原本的1.5,i会输出成1,i+i是2,由此可见强制转换数据类型会造成一些数据的丢失。
	Console.ReadLine();

//Java
	int i = 1;
	string s = (string)i;
	//由于i是int格式,所以i+i会输出2,但是这里将i(int)强转为s(string)
	//string格式的“+”是拼接,所以会输出11
	System.out.println(i+i);
	System.out.println(s+s);

Data structure-Baidu Encyclopedia

Guess you like

Origin blog.csdn.net/hu1262340436/article/details/108705099