当前位置:网站首页>[go record] start go language from scratch -- make an oscilloscope with go language (I) go language foundation

[go record] start go language from scratch -- make an oscilloscope with go language (I) go language foundation

2022-07-08 00:51:00 Ah Dan of maker Association

I participated in a challenge today , Starting from scratch GO Language , For a week GO Language development of a serial port oscilloscope .
 Insert picture description here
I haven't been in contact with GO Language , It's just C/C++, Learn from scratch GO, expect 8 Fast hours .
Use this for learning videos : Learning video

GO Language benefits : Simple and easy to use .
Dachang road , Yes C The foundation is easy to take off .
The goal is
 Insert picture description here
GO grammar : Insert picture description here
GO Language variables
 Insert picture description here
Be similar to C Enumeration of languages :
 Insert picture description here
Returns two values :
 Insert picture description here
 Insert picture description here
 Insert picture description here
init and import Guide pack
 Insert picture description here
 Insert picture description here
 Insert picture description here

Be similar to include, stay GO It's called guide bag

 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here
Basic pointer ( Did you learn C You can skip )
 Insert picture description here

defer( No define)
Finally execute in the form of stack .( It is roughly to set a stack in the function , Execute first, press in first , After the function runs , Out of the stack , The first is the last )
Follow the principle of "first in, second out" .
 Insert picture description here
 Insert picture description here
 Insert picture description here
return The following statement is executed first .defer Finally, execute .

for loop :
 Insert picture description here
len Calculate the length of the array :

The array length should match  Insert picture description here
 Insert picture description here
// What is passed is reference passing , It's a pointer ( Similar to array name , The type is int[])

 Insert picture description here
slice Four methods of :
 Insert picture description here
%v Is to print out variables variable It means , Joint output [].

 Insert picture description here
Four statements slice The way :
by make() add to
 Insert picture description here
slice Slice addition and interception :
Capacity and length are different , Insert picture description here
 Insert picture description here
The length is indeed 3, But capacity is an illegal pointer ptr Values outside ( from make The third parameter determines ), Want to operate the first one behind , Have to use append( Slice name [],2) It means appending a value to the slice name , by 2,

Reuse append( Slice name [],3) It can be added as the data of the fifth capacity , When it comes to the fifth or more , Reuse append( Slice name [],2) You can open up the length and capacity , The development size is the previous cap The capacity of ( Opened up at one time 5 individual , In an inch of land, an inch of gold flash Don't like to play like this ) Insert picture description here

copy function :
 Insert picture description here
map Three declaration definitions of :
 Insert picture description here
Now this is an empty map(==nil( Equivalent to NULL))
 Insert picture description here
map usage :
 Insert picture description here

原网站

版权声明
本文为[Ah Dan of maker Association]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/189/202207072228173235.html