栈区堆区
struct test
{
int a;
} // 这样还没在内存中开辟控件,包括任何内存都没
struct test t1; //这个是在栈区
struct test * t2 = (struct test *)malloc(sizeof(struct test)); //堆区栈的数据可以共享
int a = 3;
int b = 3;栈指针和堆指针
Golang特性
Last updated
struct test
{
int a;
} // 这样还没在内存中开辟控件,包括任何内存都没
struct test t1; //这个是在栈区
struct test * t2 = (struct test *)malloc(sizeof(struct test)); //堆区int a = 3;
int b = 3;Last updated
int* ptr;
void test(){
int a;
ptr=&a;
}
int main(){
test();
*ptr=1;
return 0;
}int* test(){
int a;
return &a;
}
int main(){
int* ptr=test();
*ptr=1;
return 0;
}var global *int
func f() {
var x int
x = 1
global = &x
}
func g() {
y := new(int)
*y = 1
}$ go build -gcflags '-m -l' main.go