结构体指针赋值

//方法1:可以给p分配一段内存空间,并使其指向此空间:

#include

main()
{
struct abc{
int a;};
struct abc *p;

p=(struct abc *)malloc(sizeof(struct abc));
p->a = 1;
printf("%d\n",p->a);
}
 
  
 
  

 
  
//方法2:可以让p指向一个已存在的内存空间:

#include

main()
{
struct abc{
int a;};
struct abc *p;

struct abc temp;
p=&temp;
p->a = 1;
printf("%d\n",p->a);
}

你可能感兴趣的:(C语言)