【发布时间】:2020-06-10 00:20:16
【问题描述】:
我做了一个程序来理解结构的概念并从函数返回结构
struct student
{
char name[20];
int age;
char subject[20];
int marks;
int rollno;
}sheet;
struct student display()
{
sheet.name[20]="Swathi";
sheet.age=21;
sheet.subject[20]="Mathematics";
sheet.marks=85;
printf("Enter roll no.:");
scanf("%d",&sheet.rollno);
}
int main()
{
struct student sheet1;
sheet1=display();
printf("Name:%s",sheet.name);
printf("Age:%d",sheet.age);
}
我收到 2 条警告消息
warning: assignment makes integer from pointer without a cast [-Wint-conversion]
sheet.name[20]="Swathi";
warning: assignment makes integer from pointer without a cast [-Wint-conversion]
sheet.subject[20]="Mathematics";
为什么会这样?我应该如何改变这个?
【问题讨论】:
标签: c function struct structure