Home>Article>Backend Development> What is the difference between c language and go language?
Differences: 1. The extensions of C language source files are ".h" and ".c", and the extensions of Go language source files are ".go". 2. In C language, code is managed through files, while in Go language, code is managed through packages. 3. There are a total of 32 keywords in C language and a total of 25 keywords in Go language.
The operating environment of this tutorial: windows7 system, c99&&GO version 1.18, Dell G3 computer.
File extension | Source type |
---|---|
.h | Header file, storing code declaration |
.c | C language source file, storing code implementation |
File extension | Source type |
---|---|
.go | Go language source file, storing code Implementation |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
---|---|---|---|---|---|---|---|
##if | ##else | ##switchcase | default | break | return | ##goto | ##do | while
for | ##continue | typedefstruct | enumunion | char | short | ||
#long | float | double | void | sizeof | ##signed | unsigned | |
auto | registerstatic | externvolatile | There are a total of 25 in Go language Keywords |
5 | 6 | 7 | 8 | ##if | |||
---|---|---|---|---|---|---|---|
switch | ##case | default | ##break | #return | ##goto | fallthrough | for | ##continue
type | struct | var | constmap | funcinterface | rangeimport | packagedefer | |
select | chan | ||||||
Data type comparison |
Each data type in C language occupies memory space
Type
32-bit compiler
1 | int | |
---|---|---|
float | 4 | |
double | 8 | |
short | 2 | |
long | 4 | |
long long | 8 | |
##void* | 4 | 8 |
Type | 32-bit compiler | 64 Bit compiler | essence |
---|---|---|---|
1 | 1 | signed char/unsigned char | |
2 | 2 | signed short/unsigned short | |
4 | 4 | signed int/unsigned int | |
8 | 8 | signed long long int/unsigned long long int | |
1 | 1 | uint8/unsigned char | |
4 | 4 | int32/signed int | |
4 | 8 | The length is determined based on the number of machine digits | |
4 | 8 | Determine the length uint32/uint64 according to the number of machine digits | |
4 | 4 | float | |
8 | 8 | double | |
1 | 1 | Integer type of char type | |
1 | 1 | char type integer |
##Get the following implementation code
// 第8行到35行 typedef signed char int8; typedef unsigned char uint8; typedef signed short int16; typedef unsigned short uint16; typedef signed int int32; typedef unsigned int uint32; typedef signed long long int int64; typedef unsigned long long int uint64; typedef float float32; typedef double float64; #ifdef _64BIT typedef uint64 uintptr; typedef int64 intptr; typedef int64 intgo; // Go's int typedef uint64 uintgo; // Go's uint #else typedef uint32 uintptr; typedef int32 intptr; typedef int32 intgo; // Go's int typedef uint32 uintgo; // Go's uint #endif #ifdef _64BITREG typedef uint64 uintreg; #else typedef uint32 uintreg; #endif // 第153行到157行 enum { true = 1, false = 0, };
So Brother Jiang taught you C language earlier In order to allow you to understand the implementation code of Go today, you should know what it is and why it is doneComparison of constant variables
数据类型 变量名称 = 值; const 数据类型 常量名称 = 值;
var 变量名称 数据类型 = 值; const 变量名称 数据类型 = 值;
Multi-line comments
/*Commented content* /
Example | ||
---|---|---|
A B | - | |
A - B | * | |
A * B | / | |
B / A | ##% | Find the remainder |
increment | ||
-- | Decrement | |
##==== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
!= | Checks whether the two values are not equal, returns True if they are not equal, otherwise returns False. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> | Check whether the left value is greater than the right value, if so, return True, otherwise return False. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check whether the left value is less than the right value, if so, return True, otherwise return False. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##>= | Check whether the left value is greater than or equal to the right value, if so, return True, otherwise return False. | A >= B | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
## | Check whether the left value is less than or equal to the right value, if so, return True, otherwise return False. | A | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
int main(){ /* 0110 a &^1011 b 如果b位位1,那么结果为0, 否则结果为a位对应的值 ---------- 0100 */ a1 := 6 b1 := 11 res1 := a1 &^ b1 fmt.Println("res1 = ", res1) // 4 /* 1011 a &^1101 b 如果b位位1,那么结果为0, 否则结果为a位对应的值 ---------- 0010 */ a2 := 11 b2 := 13 res2 := a2 &^ b2 fmt.Println("res2 = ", res2) // 2 }
流程控制语句对比
函数和方法对比
返回值类型 函数名称(形参列表) { 函数体相关语句; return 返回值; }
func 函数名称(形参列表)(返回值列表) { 函数体相关语句; return 返回值; }
func (接收者 接受者类型)函数名称(形参列表)(返回值列表) { 函数体相关语句; return 返回值; } 编程思想对比
更多编程相关知识,请访问:编程视频!! |
The above is the detailed content of What is the difference between c language and go language?. For more information, please follow other related articles on the PHP Chinese website!