以int 为例子. 适合int系列, float double .
不适用于字符串.
``` go
package main
//#include <stdio.h>
//static int m;
//int* get_m_addr(){return &m;}
//void show_m(){printf("m=%d\n",m);}
//void set_m(void *p,int x) {*(int*)p = x;}
import "C"
import "unsafe"
func main() {
t := C.get_m_addr()
*t = 5
C.show_m();
x := 100
*t = C.int(x)
C.show_m()
y := 200
C.set_m(unsafe.Pointer(t),C.int(y))
C.show_m()
}
```
有疑问加站长微信联系(非本文作者))
![](https://static.golangjob.cn/static/img/footer.png?imageView2/2/w/280)