Bootstrap

C语言指针结构体数组测试

#include "stdio.h"

struct person {
	char name;
	int age;
} ;

struct person Person1[10] = { {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}
};

struct person Person2[10] = {{23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}, {23, 'e'}
};

void  function (person *a, person  *b) {
	int cnt = 0 ;
	for (cnt = 0; cnt < 10; cnt++) {
		a[cnt].age = 10;
		a[cnt].name = 'a';
		b[cnt].age = 10;
		b[cnt].name = 'b';
	}

}

int main() {

	int a = 10;
	int b;
	function(&Person1[0], &Person2[0]);
	for (b = 0; b < 10; b++) {
		printf("%d %c\n", Person1[b].age, Person1[b].name);
		printf("%d %c\n", Person2[b].age, Person2[b].name);
		printf("\n");
	}

	printf("%d\n", a);
	return 0;
}

;