Use the pointer variable pointing to the structure variable to output the information of the members in the structure variable

Code area

#include<stdio.h>
#include<string.h>
main()
{
 struct student
 {
  long num;
  char name[10];
 }stu1,*p;
 p=&stu1;
 stu1.num=100;
 strcpy(stu1.name,"jenney");  //此处的赋值方法格外注意
 printf("%ld   %s\n",(*p).num,(*p).name); //次数用p->num的形式也可!
}

A pointer variable pointing to a structure object can point to either a structure variable or an element of a structure array; the base type of the pointer variable must be the same type as the structure variable

Published 57 original articles · Liked 54 · Visits 2370

Guess you like

Origin blog.csdn.net/September_C/article/details/104908990