Structure - Statements - Initialization - Member Access - mass participation

statement:

struct stu
{
	char name[20]={0};
	int age=0;
	char sex[5]={0};
	float score=0;
}student;


typedef struct stu
{
	char name[20]={0};
	int age=0;
	char sex[5]={0};
	float score=0;
}student;

Maybe different kinds of declarative approach in that a student is a first structure variables, while the second is the structure type of student names, the reason is because the second front typedef, typedef type is renamed, so produce different .

initialization:

struct stu student={0,0,0};
struct stu students[3] = {{9801,”zhang”,20},{9802,”wang”,19},{9803,”zhao”,18}};

Member Access:

	printf("%s\n"student.name);//student为变量
	printf("%s\n",(*student).name);//student为指针变量
	printf("%d\n",student->age);//student为指针变量

Structure variable structure when members get access to most of us are not, but get a pointer to a structure pointer.

Parameter passing:

struct stu
{
  int num;
  char name[10];
  int age;
}p;
void fun_1(struct stu *p)
{
	printf("%s\n",(*p).name);
	printf("%d\n",p->age);
	return;
}

void fun_2(struct stu p)
{
	printf("%s\n"p.name);
	return;
}

int main()
{
  	scanf("%d",&p.num);
	scanf("%s",&p.name);
	scanf("%d",&p.age);
  fun_1(p);
  fun_2(p);
  return 0;
  }

For the above two kinds of mass participation way, we try to choose first, because when the function parameter passing. Parameters need to push, if you pass a structure of an object when the structure is too large, the parameters onto the stack when the system overhead is too large, will cause performance degradation.

Published 13 original articles · won praise 21 · views 9860

Guess you like

Origin blog.csdn.net/Shangxingya/article/details/104254074