``` go
package main
//#include <stdio.h>
//#include <string.h>
//#include <malloc.h>
//static char name[30]={0};
//char* get_name_addr(){return name;}
//void show_name(){printf("name=%s\n",name);}
import "C"
import "unsafe"
func main() {
t := C.get_name_addr()
cs := C.CString("abcd")
defer C.free(unsafe.Pointer(cs)) //字符串这样要注意.
C.strcpy(t,cs)
//C.strcpy((*C.char)(unsafe.Pointer(t)),cs)
//C.strcpy((*C.char)(unsafe.Pointer(t)),(*C.char)(unsafe.Pointer(cs)))
C.show_name()
}
```
输出
```
abcd
```
有疑问加站长微信联系(非本文作者))