go与c区别

显示版本

gcc --version

go version

包含头文件

#include <stdio.h>

import "fmt"

释放内存

c: free()

go: 不需要,系统自动回收

全局变量

/* in foo.c, outside of any function: */
int x = 7;

/* to declare in bar.c: */
extern int x;
// foo.go:
package foo

// capitalized top-level identifiers are exported:
var X = 7

// bar.go:
package bar
import foo

// package scope:
var y = 3

func baz() {
  // local scope:
  var z = 5

  fmt.Println(foo.X + y + z)
}

自增自减

c: i --i i i--

go:i++ i--

地址

int i = 3;
int* ptr = &i;
i := 3
var ptr *int
ptr = &i
ptr2 := &i

c:ptr == NULL

go:ptr == nil

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×