#include<bits/stdc++.h>
using namespace std;
struct type{
int a;
int b;
};
int main(void)
{
type *T = (type*)malloc(sizeof(type));//分配一个有着type大小的内存区域 并将这个地址返回为type指针类型
T->a = 0;
T->b = 0;
cout<<T->a<<" "<<T->b<<endl;
type A,*t = &A;//要是不先声明A来个给t的地址进行初始化 t就是一个野指针 访问野指针会有无法预计的后果
t->a = 1;
t->b = 1;
cout<< t->a <<" "<< t->b <<endl;
return 0;
}
关于使用malloc声明指针 和 直接声明指针的区别
最新推荐文章于 2021-09-06 15:08:53 发布