The first lesson was reviewed c Some knowledge of language , It also introduces the course of data structure .


1, References and function calls :

1.1 quote : Create a “ quote ”, Its role is to give an alias to a variable . This is C++ Yes C An important supplement to language .

The usage is very simple :

int a = 5;

int &b = a;

b yes a alias ,b And a Represents the same variable , Occupy the same storage unit in memory , Has the same address .

matters needing attention :

* Declare a reference , It must also be initialized , And declare which variable it represents .( Initialization is not required as a function parameter )
* After declaring a reference , Can no longer be used as a reference to another variable .
     3. Cannot create reference array .

1.2 function call :

In fact, we understand the reference through the function
void Myswap1(int a,int b) { int c = a; a = b; b = c; } void Myswap2(int &a,int
&b) { int c = a; a = b; b = c; } void Myswap3(int *pa,int *pb) { int c = *pa;
*pa = *pb; *pb = c; }
These three functions are very simple , The first one just passed in the value , Do not change global variables ; And the third one is familiar , That's the address , Easy to operate . Still “ pass by value ” The way , It's just the address of the variable ;
That two completely changed these things , Reference as function parameter , The arguments passed in are variables , It's not a number , In the real sense “ Transfer variables ”.


2, Arrays and pointers :

This part is relatively simple , It's basic knowledge .

primary coverage :

1, A function passing an array is passing a pointer , We all know that , So when you pass it on, you write it arr[], How much is written in it , Or not , It doesn't matter , Then you must put a variable to pass in the length of the array .

2, And then there is , definition :int arr[5], You can't report wrong when you visit the border , But it certainly doesn't make sense logically . That's good typedef int
INTARR[3]; Cross border visits , stay vs An error was reported at the meeting , it is to be noted that .

3, Again, what's the difference between pointer and array name ? These are two things , Maybe you didn't notice .

first : The pointer can be self incremented , Array names don't work , Because it's constant .

second : The address is different , Although the name [n], Can be used in this way , But the array name address is the first element address . The pointer address is the address of that pointer , The first element address is stored in the pointer .

third :sizeof(), The space is different , An array takes up as much space as an array . The pointer is four bytes .

They are two things , So many differences are the embodiment of essential differences .

3, structural morphology :

It is also the basic operation , It's basically this thing :
typedef struct Date { int Year; int Month; int Day; struct Date *pDate; }Date,
1, Only when there is no pointer to itself can the first line not be named .

2, You can't define your own , If you can, isn't the space infinite . Simple logic


I'm not used to the pointer , Or write Date * It's more pleasing to the eye

3, Some students didn't pay attention : How to access things in the access structure ?

Date. This form , Or there is a pointer to this node p sure p-> This form , Don't make a mistake .


4, There is also the structure of physical fitness directly so assigned :

   Date d1 = {2018,9,11};

I didn't even know , In the past, I used to assign values one by one .


5, also , I want to write about the advantages of structure ..

This piece may not be written well , Because it's not what the teacher said ..

For example, student achievement , If you don't use the structure , One of our students may have more than a dozen messages , It's very cumbersome to define variables and operations , Data structures have a loose feel . It's better to use a structure , Whether it is the readability, portability or maintainability of the program , All of them have been promoted . There are also function calls , A considerable number of parameters are passed in , Want to operate or return , That's a lot of trouble . Now just pass in one structure , The operation is extremely simple . In summary, it is easy to operate , Focus on and use , The properties of objects are organized organically . The function is replaced by modifying the structure member variables ( Entrance parameters ) Redefinition of .

Basically that's it .

6, And that's it :typedef int INTARR[3]; This defines a data type directly , Count Reg 3 Array of , And then use it directly :

INTARR arr1;


The memory is over C Language reserves knowledge , Then the basic concept of data structure is introduced


Data structure is a subject that studies the operating objects of computers and their relations and operations in non numerical programming problems .

data : It is the symbolic representation of objective things , In a computer, a general term for symbols that can be input into a computer and processed .

data elements : Basic unit of data

data item : The smallest indivisible unit of data

data object : A collection of data elements of the same nature .

give an example : Animals are data , An animal is a data element , Dogs and cats are data objects , Colors can be data items .


There is a relationship between data elements , This relationship becomes structure .

Four basic structures :

aggregate : It has no relationship except that it belongs to the same set .

linear structure : One to one relationship

tree structure : One to many relationship

Graphic structure : Many to many relationship





©2019-2020 Toolsou All rights reserved,
One is called “ Asking for the train ” A small village Finally got the train Spring Boot Lesson 16 :SpringBoot Implementation of multithreading with injection class Chrome OS, For programmers and Windows What does it mean ? Internet Marketing JAVA Convert a string to a numeric type I've been drinking soft water for three years ? What is the use of soft water and water softener You don't know ——HarmonyOS Talking about uni-app Page value transfer problem JavaScript Medium Call and ApplySparkSQL Achieve partition overlay write Character recognition technology of vehicle license plate based on Neural Network