C語言定義結構體指針數組並初始化;里面全是結構體的地址


#include <stdio.h>
#include <string.h>
struct tells;//聲明結構體
struct info
{
	char *infos;
};
typedef struct Books
{
	char *name;
	int page;
	struct info *pinfo;
	struct tells *tel;
}BK;
struct tells{
	char *age;
};
void pout(struct Books *b);
void pouts(struct Books *b[], int n);
int main(){
	struct info str = {"信息內容描述"};
	BK book1 = {"C鴛鴦",100,&str};
	BK book2 = {"Java",200,&str};
	BK *b = &book1;
	//定義結構體數組
	BK arr_book[] = {book1, book2};
	//定義一個指向結構體數組的結構體指針
	BK *bookp = arr_book;//數組首地址就是指針地址
	int i;
	for(i=0;i<2;i++){
		pout(bookp+1);
		printf("*******************************\n");
	}
	//定義結構體指針數組並初始化;里面全是結構體的地址
	BK *arr_bookp[]= {b,&book2};
	pouts(arr_bookp,2);

	return 0;
}
void pout(BK *b){
	printf("name:%s page:%d info:%s\n", b->name,b->page,b->pinfo->infos);
}
void pouts(BK *b[], int n){
	printf("結構圖體指針數組大小sizeof:%ld\n",sizeof(b));
	int i=0;
	for(;i<n;i++){
	   pout(b[i]);
	}
}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM