c刚入门,有一个问题求教
如以下代码所示
#include <stdio.h>
#include <stdlib.h>
struct Date
{
int year;
int month;
int day;
};
struct Book
{
char title[128];
char author[40];
float price;
struct Date date;
char publisher[40];
};
//书本信息
struct Book getInput(struct Book book);
void printbook(struct Book book);
//函数声明
struct Book getInput(struct Book book)
{
printf(“请输入书名:”);
scanf("%s", book.title);
printf(“请输入作者:”);
scanf("%s", book.author);
printf(“请输入售价:”);
scanf("%f", &book.price);
printf(“请输入出版日期:”);
scanf("%d,%d,%d",&book.date.year,&book.date.month,&book.date.day);
printf(“请输入出版社:”);
scanf("%s", book.publisher);
return book;
};
void printbook(struct Book book)
{
printf(“书名:%s\n”, book.title);
printf(“作者:%s\n”, book.author);
printf(“售价:%.2f\n”, book.price);
printf(“出版日期:%d-%d-%d\n”, book.date.year,book.date.month,book.date.day);
printf(“出版社:%s\n”, book.author);
}
int main(void)
{
struct Book b1,b2;
printf(“请输入第一本书的信息\n”);
b1 = getInput(b1);
putchar(’\n’);
printf(“请输入第二本书的信息\n”);
b2 = getInput(b2);
printf(“录入完毕,现在开始验证\n”);
printbook(b1);
printbook(b2);
return 0;
}
这是一段出自小甲鱼c语言教程的代码,本人跟着码了一边代码以后不太明白为什么scanf那里需要加&,而printf这里不需要加&
希望有大佬帮忙解答