代码
struct book{
int id;
char* name;
};
static void readData(int fd, void * privdata) {
struct book * b = privdata;
printf("============================\n");
printf("readData fd=%d, book.id = %d, name=%s , Address =%p \n", fd,b->id,b->name,b);
}
int main(){
char * name = "c++";
struct book b = {100,name};
readData(5,&b);
return(0);
}
输出
readData fd=5, book.id = 100, name=c++ , Address =000000000061FDB0
初始化方式1
char * name = "c++";
struct book b = {100,name};
方式2
struct book b2 = {.name="c primer",.id=10};